diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..d587999e1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[Makefile] +indent_style = tab + +[*.sh] +indent_style = tab diff --git a/.gitignore b/.gitignore index 920af7622..62f28681c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -*.swp -*.swo -*.pyc vendor +.glide diff --git a/Makefile b/Makefile index 31236551f..19ae42600 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ build: # test.sh requires that we run the installed cmds, must not be out of date test: install - find . -name test.sock -exec rm {} \; + find . -path ./vendor -prune -o -name *.sock -exec rm {} \; @ go test -p 1 `${NOVENDOR}` @ bash tests/test.sh @@ -30,7 +30,7 @@ lint: @ go get -u github.com/golang/lint/golint @ for file in $$(find "." -name '*.go' | grep -v '/vendor/' | grep -v '\.pb\.go'); do \ golint -set_exit_status $${file}; \ - done; + done; test_integrations: get_vendor_deps install test diff --git a/client/grpc_client.go b/client/grpc_client.go index 423936698..25783101e 100644 --- a/client/grpc_client.go +++ b/client/grpc_client.go @@ -51,7 +51,7 @@ RETRY_LOOP: if cli.mustConnect { return err } - log.Warn(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr)) + cli.Logger.Error(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr)) time.Sleep(time.Second * 3) continue RETRY_LOOP } @@ -93,7 +93,7 @@ func (cli *grpcClient) StopForError(err error) { } cli.mtx.Unlock() - log.Warn(fmt.Sprintf("Stopping abci.grpcClient for error: %v", err.Error())) + cli.Logger.Error(fmt.Sprintf("Stopping abci.grpcClient for error: %v", err.Error())) cli.Stop() } diff --git a/client/local_client.go b/client/local_client.go index 4bdcffad1..37f76abb3 100644 --- a/client/local_client.go +++ b/client/local_client.go @@ -22,7 +22,7 @@ func NewLocalClient(mtx *sync.Mutex, app types.Application) *localClient { mtx: mtx, Application: app, } - cli.BaseService = *cmn.NewBaseService(log, "localClient", cli) + cli.BaseService = *cmn.NewBaseService(nil, "localClient", cli) return cli } diff --git a/client/log.go b/client/log.go deleted file mode 100644 index 146bf1273..000000000 --- a/client/log.go +++ /dev/null @@ -1,7 +0,0 @@ -package abcicli - -import ( - "github.com/tendermint/tmlibs/logger" -) - -var log = logger.New("module", "abcicli") diff --git a/client/socket_client.go b/client/socket_client.go index ebcfb44b7..dd3e2903b 100644 --- a/client/socket_client.go +++ b/client/socket_client.go @@ -53,7 +53,8 @@ func NewSocketClient(addr string, mustConnect bool) (*socketClient, error) { resCb: nil, } cli.BaseService = *cmn.NewBaseService(nil, "socketClient", cli) - + // FIXME we are loosing "Starting socketClient" message here + // add logger to params? _, err := cli.Start() // Just start it, it's confusing for callers to remember to start. return cli, err } @@ -70,7 +71,7 @@ RETRY_LOOP: if cli.mustConnect { return err } - log.Warn(fmt.Sprintf("abci.socketClient failed to connect to %v. Retrying...", cli.addr)) + cli.Logger.Error(fmt.Sprintf("abci.socketClient failed to connect to %v. Retrying...", cli.addr)) time.Sleep(time.Second * 3) continue RETRY_LOOP } @@ -107,7 +108,7 @@ func (cli *socketClient) StopForError(err error) { } cli.mtx.Unlock() - log.Warn(fmt.Sprintf("Stopping abci.socketClient for error: %v", err.Error())) + cli.Logger.Error(fmt.Sprintf("Stopping abci.socketClient for error: %v", err.Error())) cli.Stop() } @@ -147,7 +148,7 @@ func (cli *socketClient) sendRequestsRoutine(conn net.Conn) { cli.StopForError(fmt.Errorf("Error writing msg: %v", err)) return } - // log.Debug("Sent request", "requestType", reflect.TypeOf(reqres.Request), "request", reqres.Request) + // cli.Logger.Debug("Sent request", "requestType", reflect.TypeOf(reqres.Request), "request", reqres.Request) if _, ok := reqres.Request.Value.(*types.Request_Flush); ok { err = w.Flush() if err != nil { @@ -175,7 +176,7 @@ func (cli *socketClient) recvResponseRoutine(conn net.Conn) { cli.StopForError(errors.New(r.Exception.Error)) return default: - // log.Debug("Received response", "responseType", reflect.TypeOf(res), "response", res) + // cli.Logger.Debug("Received response", "responseType", reflect.TypeOf(res), "response", res) err := cli.didRecvResponse(res) if err != nil { cli.StopForError(err) diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index accae9d1e..f4fe45fee 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -6,13 +6,13 @@ import ( "errors" "fmt" "io" - "log" "os" "strings" - "github.com/tendermint/abci/client" + abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/types" "github.com/tendermint/abci/version" + "github.com/tendermint/tmlibs/log" "github.com/urfave/cli" ) @@ -36,6 +36,8 @@ type queryResponse struct { // client is a global variable so it can be reused by the console var client abcicli.Client +var logger log.Logger + func main() { //workaround for the cli library (https://github.com/urfave/cli/issues/565) @@ -129,18 +131,24 @@ func main() { app.Before = before err := app.Run(os.Args) if err != nil { - log.Fatal(err.Error()) + logger.Error(err.Error()) + os.Exit(1) } } func before(c *cli.Context) error { + if logger == nil { + logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + } if client == nil { var err error client, err = abcicli.NewClient(c.GlobalString("address"), c.GlobalString("abci"), false) if err != nil { - log.Fatal(err.Error()) + logger.Error(err.Error()) + os.Exit(1) } + client.SetLogger(logger.With("module", "abci-client")) } return nil } diff --git a/cmd/counter/main.go b/cmd/counter/main.go index e7b777a8c..351e0886c 100644 --- a/cmd/counter/main.go +++ b/cmd/counter/main.go @@ -2,11 +2,12 @@ package main import ( "flag" - "log" + "os" "github.com/tendermint/abci/example/counter" "github.com/tendermint/abci/server" cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" ) func main() { @@ -17,11 +18,15 @@ func main() { flag.Parse() app := counter.NewCounterApplication(*serialPtr) + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + // Start the listener srv, err := server.NewServer(*addrPtr, *abciPtr, app) if err != nil { - log.Fatal(err.Error()) + logger.Error(err.Error()) + os.Exit(1) } + srv.SetLogger(logger.With("module", "abci-server")) // Wait forever cmn.TrapSignal(func() { diff --git a/cmd/dummy/main.go b/cmd/dummy/main.go index a1cc68aef..9e1a8112e 100644 --- a/cmd/dummy/main.go +++ b/cmd/dummy/main.go @@ -2,12 +2,13 @@ package main import ( "flag" - "log" + "os" "github.com/tendermint/abci/example/dummy" "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" ) func main() { @@ -17,19 +18,24 @@ func main() { persistencePtr := flag.String("persist", "", "directory to use for a database") flag.Parse() + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + // Create the application - in memory or persisted to disk var app types.Application if *persistencePtr == "" { app = dummy.NewDummyApplication() } else { app = dummy.NewPersistentDummyApplication(*persistencePtr) + app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy")) } // Start the listener srv, err := server.NewServer(*addrPtr, *abciPtr, app) if err != nil { - log.Fatal(err.Error()) + logger.Error(err.Error()) + os.Exit(1) } + srv.SetLogger(logger.With("module", "abci-server")) // Wait forever cmn.TrapSignal(func() { diff --git a/example/block_aware/block_aware_app.go b/example/block_aware/block_aware_app.go index e1afee968..30e115acd 100644 --- a/example/block_aware/block_aware_app.go +++ b/example/block_aware/block_aware_app.go @@ -2,11 +2,12 @@ package main import ( "flag" - "log" + "os" "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" ) func main() { @@ -15,11 +16,15 @@ func main() { abciPtr := flag.String("abci", "socket", "socket | grpc") flag.Parse() + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + // Start the listener srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication()) if err != nil { - log.Fatal(err.Error()) + logger.Error(err.Error()) + os.Exit(1) } + srv.SetLogger(logger.With("module", "abci-server")) // Wait forever cmn.TrapSignal(func() { diff --git a/example/block_aware/block_aware_test.go b/example/block_aware/block_aware_test.go index 2ce6aacf3..6d42b876e 100644 --- a/example/block_aware/block_aware_test.go +++ b/example/block_aware/block_aware_test.go @@ -1,19 +1,17 @@ package main import ( - "fmt" - "log" "strconv" "strings" "testing" - "github.com/tendermint/abci/client" + abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" + "github.com/tendermint/tmlibs/log" ) func TestChainAware(t *testing.T) { - app := NewChainAwareApplication() // Start the listener @@ -21,13 +19,15 @@ func TestChainAware(t *testing.T) { if err != nil { t.Fatal(err) } + srv.SetLogger(log.TestingLogger().With("module", "abci-server")) defer srv.Stop() // Connect to the socket client, err := abcicli.NewSocketClient("unix://test.sock", false) if err != nil { - log.Fatal(fmt.Sprintf("Error starting socket client: %v", err.Error())) + t.Fatalf("Error starting socket client: %v", err.Error()) } + client.SetLogger(log.TestingLogger().With("module", "abci-client")) client.Start() defer client.Stop() diff --git a/example/dummy/dummy_test.go b/example/dummy/dummy_test.go index 57aac4ef2..f805dd73c 100644 --- a/example/dummy/dummy_test.go +++ b/example/dummy/dummy_test.go @@ -10,9 +10,10 @@ import ( abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" - "github.com/tendermint/go-crypto" + crypto "github.com/tendermint/go-crypto" "github.com/tendermint/merkleeyes/iavl" cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" ) func testDummy(t *testing.T, app types.Application, tx []byte, key, value string) { @@ -211,10 +212,13 @@ func valsEqual(t *testing.T, vals1, vals2 []*types.Validator) { func makeSocketClientServer(app types.Application, name string) (abcicli.Client, cmn.Service, error) { // Start the listener socket := cmn.Fmt("unix://%s.sock", name) + logger := log.TestingLogger() + server, err := server.NewSocketServer(socket, app) if err != nil { return nil, nil, err } + server.SetLogger(logger.With("module", "abci-server")) // Connect to the socket client, err := abcicli.NewSocketClient(socket, false) @@ -222,6 +226,7 @@ func makeSocketClientServer(app types.Application, name string) (abcicli.Client, server.Stop() return nil, nil, err } + client.SetLogger(logger.With("module", "abci-client")) client.Start() return client, server, err @@ -230,18 +235,21 @@ func makeSocketClientServer(app types.Application, name string) (abcicli.Client, func makeGRPCClientServer(app types.Application, name string) (abcicli.Client, cmn.Service, error) { // Start the listener socket := cmn.Fmt("unix://%s.sock", name) + logger := log.TestingLogger() gapp := types.NewGRPCApplication(app) server, err := server.NewGRPCServer(socket, gapp) if err != nil { return nil, nil, err } + server.SetLogger(logger.With("module", "abci-server")) client, err := abcicli.NewGRPCClient(socket, true) if err != nil { server.Stop() return nil, nil, err } + client.SetLogger(logger.With("module", "abci-client")) return client, server, err } diff --git a/example/dummy/log.go b/example/dummy/log.go deleted file mode 100644 index 5607ca556..000000000 --- a/example/dummy/log.go +++ /dev/null @@ -1,7 +0,0 @@ -package dummy - -import ( - "github.com/tendermint/tmlibs/logger" -) - -var log = logger.New("module", "dummy") diff --git a/example/dummy/persistent_dummy.go b/example/dummy/persistent_dummy.go index 84793bc91..fb59a2724 100644 --- a/example/dummy/persistent_dummy.go +++ b/example/dummy/persistent_dummy.go @@ -6,11 +6,13 @@ import ( "strconv" "strings" + "github.com/pkg/errors" "github.com/tendermint/abci/types" - "github.com/tendermint/go-wire" + wire "github.com/tendermint/go-wire" "github.com/tendermint/merkleeyes/iavl" cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" + "github.com/tendermint/tmlibs/log" ) const ( @@ -29,6 +31,8 @@ type PersistentDummyApplication struct { // validator set changes []*types.Validator + + logger log.Logger } func NewPersistentDummyApplication(dbDir string) *PersistentDummyApplication { @@ -38,14 +42,19 @@ func NewPersistentDummyApplication(dbDir string) *PersistentDummyApplication { stateTree := iavl.NewIAVLTree(0, db) stateTree.Load(lastBlock.AppHash) - log.Notice("Loaded state", "block", lastBlock.Height, "root", stateTree.Hash()) + // log.Notice("Loaded state", "block", lastBlock.Height, "root", stateTree.Hash()) return &PersistentDummyApplication{ - app: &DummyApplication{state: stateTree}, - db: db, + app: &DummyApplication{state: stateTree}, + db: db, + logger: log.NewNopLogger(), } } +func (app *PersistentDummyApplication) SetLogger(l log.Logger) { + app.logger = l +} + func (app *PersistentDummyApplication) Info() (resInfo types.ResponseInfo) { resInfo = app.app.Info() lastBlock := LoadLastBlock(app.db) @@ -79,13 +88,16 @@ func (app *PersistentDummyApplication) CheckTx(tx []byte) types.Result { func (app *PersistentDummyApplication) Commit() types.Result { // Save appHash := app.app.state.Save() - log.Info("Saved state", "root", appHash) + app.logger.Info("Saved state", "root", appHash) lastBlock := LastBlockInfo{ Height: app.blockHeader.Height, AppHash: appHash, // this hash will be in the next block header } + + app.logger.Info("Saving block", "height", lastBlock.Height, "root", lastBlock.AppHash) SaveLastBlock(app.db, lastBlock) + return types.NewResultOK(appHash, "") } @@ -98,7 +110,7 @@ func (app *PersistentDummyApplication) InitChain(validators []*types.Validator) for _, v := range validators { r := app.updateValidator(v) if r.IsErr() { - log.Error("Error updating validators", "r", r) + app.logger.Error("Error updating validators", "r", r) } } } @@ -134,8 +146,7 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) { r, n, err := bytes.NewReader(buf), new(int), new(error) wire.ReadBinaryPtr(&lastBlock, r, 0, n, err) if *err != nil { - // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED - log.Crit(cmn.Fmt("Data has been corrupted or its spec has changed: %v\n", *err)) + cmn.PanicCrisis(errors.Wrap(*err, "cannot load last block (data has been corrupted or its spec has changed)")) } // TODO: ensure that buf is completely read. } @@ -144,12 +155,11 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) { } func SaveLastBlock(db dbm.DB, lastBlock LastBlockInfo) { - log.Notice("Saving block", "height", lastBlock.Height, "root", lastBlock.AppHash) buf, n, err := new(bytes.Buffer), new(int), new(error) wire.WriteBinary(lastBlock, buf, n, err) if *err != nil { // TODO - cmn.PanicCrisis(*err) + cmn.PanicCrisis(errors.Wrap(*err, "cannot save last block")) } db.Set(lastBlockKey, buf.Bytes()) } diff --git a/example/example_test.go b/example/example_test.go index e6edef363..85c13d7d6 100644 --- a/example/example_test.go +++ b/example/example_test.go @@ -2,7 +2,6 @@ package example import ( "fmt" - "log" "net" "reflect" "testing" @@ -12,11 +11,12 @@ import ( "golang.org/x/net/context" - "github.com/tendermint/abci/client" + abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/example/dummy" "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" ) func TestDummy(t *testing.T) { @@ -35,21 +35,22 @@ func TestGRPC(t *testing.T) { } func testStream(t *testing.T, app types.Application) { - numDeliverTxs := 200000 // Start the listener server, err := server.NewSocketServer("unix://test.sock", app) if err != nil { - log.Fatal(cmn.Fmt("Error starting socket server: %v", err.Error())) + t.Fatalf("Error starting socket server: %v", err.Error()) } + server.SetLogger(log.TestingLogger().With("module", "abci-server")) defer server.Stop() // Connect to the socket client, err := abcicli.NewSocketClient("unix://test.sock", false) if err != nil { - log.Fatal(cmn.Fmt("Error starting socket client: %v", err.Error())) + t.Fatalf("Error starting socket client: %v", err.Error()) } + client.SetLogger(log.TestingLogger().With("module", "abci-client")) client.Start() defer client.Stop() @@ -108,20 +109,20 @@ func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) { } func testGRPCSync(t *testing.T, app *types.GRPCApplication) { - numDeliverTxs := 2000 // Start the listener server, err := server.NewGRPCServer("unix://test.sock", app) if err != nil { - log.Fatal(cmn.Fmt("Error starting GRPC server: %v", err.Error())) + t.Fatalf("Error starting GRPC server: %v", err.Error()) } + server.SetLogger(log.TestingLogger().With("module", "abci-server")) defer server.Stop() // Connect to the socket conn, err := grpc.Dial("unix://test.sock", grpc.WithInsecure(), grpc.WithDialer(dialerFunc)) if err != nil { - log.Fatal(cmn.Fmt("Error dialing GRPC server: %v", err.Error())) + t.Fatalf("Error dialing GRPC server: %v", err.Error()) } defer conn.Close() diff --git a/glide.lock b/glide.lock index 614ce5a19..43375f1e5 100644 --- a/glide.lock +++ b/glide.lock @@ -1,28 +1,35 @@ -hash: 13c7dac029851e5177bf78ff26ce6ccd047360111795a9a65af4ba6a0b87f4b3 -updated: 2017-04-21T18:38:50.4243289-04:00 +hash: 8038c78e65a8b5ad4bc6ff8e74c40bd02be23e2c3c4245aff8b354e3dbdec1e2 +updated: 2017-05-05T12:30:23.699400925Z imports: - name: github.com/btcsuite/btcd - version: 583684b21bfbde9b5fc4403916fd7c807feb0289 + version: 4b348c1d33373d672edd83fc576892d0e46686d2 subpackages: - btcec +- name: github.com/go-kit/kit + version: 0873e56b0faeae3a1d661b10d629135508ea5504 + subpackages: + - log + - log/level + - log/term +- name: github.com/go-logfmt/logfmt + version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 - name: github.com/go-stack/stack - version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 + version: 7a2f19628aabfe68f0766b59e74d6315f8347d22 - name: github.com/golang/protobuf - version: 8ee79997227bf9b34611aee7946ae64735e6fd93 + version: 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8 subpackages: - proto + - ptypes/any - name: github.com/golang/snappy - version: d9eb7a3d35ec988b8585d4a0068e462c27d28380 + version: 553a641470496b2327abcac10b36396bd98e45c9 - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 -- name: github.com/mattn/go-colorable - version: d228849504861217f796da67fae4f6e347643f15 -- name: github.com/mattn/go-isatty - version: 30a891c33c7cde7b02a981314b4228ec99380cca +- name: github.com/kr/logfmt + version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 - name: github.com/pkg/errors - version: 645ef00459ed84a119197bfb8d8205042c6df63d + version: c605e284fe17294bda444b34710735b29d1a9d90 - name: github.com/syndtr/goleveldb - version: 23851d93a2292dcc56e71a18ec9e0624d84a0f65 + version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: - leveldb - leveldb/cache @@ -42,31 +49,27 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-crypto - version: 9b95da8fa4187f6799558d89b271dc8ab6485615 + version: 524ba917a3a1636f21ab2c0bf76b6526903ab879 - name: github.com/tendermint/go-wire - version: 334005c236d19c632fb5f073f9de3b0fab6a522b + version: b53add0b622662731985485f3a19be7f684660b8 subpackages: - data -- name: github.com/tendermint/log15 - version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6 - subpackages: - - term - name: github.com/tendermint/merkleeyes - version: 6fd69aa0871a4e685a5570aa7ab3d12e4068a722 + version: d0aa363fd4e015e509038c3a0ec493bc62ee0b8a subpackages: - iavl - name: github.com/tendermint/tmlibs - version: df250b69416a35a943a6e2a92118667e9ef031d4 + version: a9a96064a0a494ef6a13c38b4395c20abee64996 subpackages: - common - db - - logger + - log - merkle - process - name: github.com/urfave/cli - version: 0bdeddeeb0f650497d603c4ad7b20cfe685682f6 + version: ab403a54a148f2d857920810291539e1f817ee7b - name: golang.org/x/crypto - version: 7c6cc321c680f03b9ef0764448e780704f486b51 + version: 5a033cc77e57eca05bdb50522851d29e03569cbe subpackages: - nacl/secretbox - openpgp/armor @@ -75,7 +78,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: 61557ac0112b576429a0df080e1c2cef5dfbb642 + version: feeb485667d1fdabe727840fe00adc22431bc86e subpackages: - context - http2 @@ -84,26 +87,36 @@ imports: - internal/timeseries - lex/httplex - trace -- name: golang.org/x/sys - version: d75a52659825e75fff6158388dddc6a5b04f9ba5 +- name: golang.org/x/text + version: 470f45bf29f4147d6fbd7dfd0a02a848e49f5bf4 + subpackages: + - secure/bidirule + - transform + - unicode/bidi + - unicode/norm +- name: google.golang.org/genproto + version: 411e09b969b1170a9f0c467558eb4c4c110d9c77 subpackages: - - unix + - googleapis/rpc/status - name: google.golang.org/grpc - version: cbcceb2942a489498cf22b2f918536e819d33f0a + version: 844f573616520565fdc6fb4db242321b5456fd6d subpackages: - codes - credentials + - grpclb/grpc_lb_v1 - grpclog - internal + - keepalive - metadata - naming - peer - stats + - status - tap - transport testImports: - name: github.com/davecgh/go-spew - version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 + version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 subpackages: - spew - name: github.com/pmezard/go-difflib @@ -111,7 +124,7 @@ testImports: subpackages: - difflib - name: github.com/stretchr/testify - version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 + version: 4d4bfba8f1d1027c4fdbe371823030df51419987 subpackages: - assert - require diff --git a/glide.yaml b/glide.yaml index 2876b0e51..bd97a4a87 100644 --- a/glide.yaml +++ b/glide.yaml @@ -3,6 +3,7 @@ import: - package: github.com/golang/protobuf subpackages: - proto +- package: github.com/pkg/errors - package: github.com/tendermint/go-crypto version: develop - package: github.com/tendermint/go-wire @@ -12,11 +13,11 @@ import: subpackages: - iavl - package: github.com/tendermint/tmlibs - version: develop + version: log subpackages: - common - db - - logger + - log - merkle - process - package: github.com/urfave/cli diff --git a/server/log.go b/server/log.go deleted file mode 100644 index 887c9ed6d..000000000 --- a/server/log.go +++ /dev/null @@ -1,7 +0,0 @@ -package server - -import ( - "github.com/tendermint/tmlibs/logger" -) - -var log = logger.New("module", "abci-server") diff --git a/server/socket_server.go b/server/socket_server.go index 9933829c7..f8d6f54a9 100644 --- a/server/socket_server.go +++ b/server/socket_server.go @@ -40,6 +40,8 @@ func NewSocketServer(protoAddr string, app types.Application) (cmn.Service, erro conns: make(map[int]net.Conn), } s.BaseService = *cmn.NewBaseService(nil, "ABCIServer", s) + // FIXME we are loosing "Starting ABCIServer" message here + // add logger to params? _, err := s.Start() // Just start it return s, err } @@ -94,15 +96,15 @@ func (s *SocketServer) acceptConnectionsRoutine() { // semaphore <- struct{}{} // Accept a connection - log.Notice("Waiting for new connection...") + s.Logger.Info("Waiting for new connection...") conn, err := s.listener.Accept() if err != nil { if !s.IsRunning() { return // Ignore error from listener closing. } - log.Crit("Failed to accept connection: " + err.Error()) + s.Logger.Error("Failed to accept connection: " + err.Error()) } else { - log.Notice("Accepted a new connection") + s.Logger.Info("Accepted a new connection") } connID := s.addConn(conn) @@ -119,18 +121,18 @@ func (s *SocketServer) acceptConnectionsRoutine() { // Wait until signal to close connection errClose := <-closeConn if err == io.EOF { - log.Warn("Connection was closed by client") + s.Logger.Error("Connection was closed by client") } else if errClose != nil { - log.Warn("Connection error", "error", errClose) + s.Logger.Error("Connection error", "error", errClose) } else { // never happens - log.Warn("Connection was closed.") + s.Logger.Error("Connection was closed.") } // Close the connection err := s.rmConn(connID, conn) if err != nil { - log.Warn("Error in closing connection", "error", err) + s.Logger.Error("Error in closing connection", "error", err) } // <-semaphore diff --git a/tests/test.sh b/tests/test.sh old mode 100644 new mode 100755 diff --git a/tests/test_app/app.go b/tests/test_app/app.go index 7cff57107..a88a05fd6 100644 --- a/tests/test_app/app.go +++ b/tests/test_app/app.go @@ -6,8 +6,9 @@ import ( "os" "time" - "github.com/tendermint/abci/client" + abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/types" + "github.com/tendermint/tmlibs/log" "github.com/tendermint/tmlibs/process" ) @@ -37,6 +38,8 @@ func startClient(abciType string) abcicli.Client { if err != nil { panic("connecting to abci_app: " + err.Error()) } + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + client.SetLogger(logger.With("module", "abcicli")) return client } diff --git a/tests/test_app/test.sh b/tests/test_app/test.sh index a0f2c3ce6..0620b4767 100755 --- a/tests/test_app/test.sh +++ b/tests/test_app/test.sh @@ -3,14 +3,19 @@ set -e # These tests spawn the counter app and server by execing the ABCI_APP command and run some simple client tests against it -ROOT=$GOPATH/src/github.com/tendermint/abci/tests/test_app -cd $ROOT +# Get the directory of where this script is. +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +# Change into that dir because we expect that. +cd "$DIR" # test golang counter -ABCI_APP="counter" go run *.go +ABCI_APP="counter" go run ./*.go # test golang counter via grpc -ABCI_APP="counter -abci=grpc" ABCI="grpc" go run *.go +ABCI_APP="counter -abci=grpc" ABCI="grpc" go run ./*.go # test nodejs counter # TODO: fix node app diff --git a/tests/test_cli/test.sh b/tests/test_cli/test.sh index a770730be..4266dd16f 100644 --- a/tests/test_cli/test.sh +++ b/tests/test_cli/test.sh @@ -1,6 +1,12 @@ #! /bin/bash -cd $GOPATH/src/github.com/tendermint/abci +# Get the root directory. +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done +DIR="$( cd -P "$( dirname "$SOURCE" )/../.." && pwd )" + +# Change into that dir because we expect that. +cd "$DIR" || exit function testExample() { N=$1 @@ -10,17 +16,17 @@ function testExample() { echo "Example $N" $APP &> /dev/null & sleep 2 - abci-cli --verbose batch < $INPUT > "${INPUT}.out.new" - killall "$APP" + abci-cli --verbose batch < "$INPUT" > "${INPUT}.out.new" + killall "$APP" - pre=`shasum < "${INPUT}.out"` - post=`shasum < "${INPUT}.out.new"` + pre=$(shasum < "${INPUT}.out") + post=$(shasum < "${INPUT}.out.new") if [[ "$pre" != "$post" ]]; then echo "You broke the tutorial" - echo "Got:" + echo "Got:" cat "${INPUT}.out.new" - echo "Expected:" + echo "Expected:" cat "${INPUT}.out" exit 1 fi