From 78fe37a03241b5f58c94486e59a3acd235445f3f Mon Sep 17 00:00:00 2001
From: Silas Davis <silas@erisindustries.com>
Date: Mon, 9 Jan 2017 12:00:43 +0000
Subject: [PATCH] Remove eris-logger references from eris-db server

---
 client/cmd/eris-client.go          | 10 ------
 cmd/serve.go                       | 18 +++++------
 consensus/tendermint/tendermint.go | 51 +++++++++++++++---------------
 core/core.go                       |  1 +
 event/event_cache.go               |  4 +--
 event/event_cache_test.go          |  4 +--
 event/events.go                    | 28 ++++++++--------
 logging/convention.go              | 10 ++++++
 logging/lifecycle/lifecycle.go     | 10 +++++-
 logging/structure/structure.go     |  2 ++
 manager/eris-mint/eris-mint.go     | 21 ++++++------
 manager/eris-mint/pipe.go          | 47 +++++++++++----------------
 manager/manager.go                 |  8 ++---
 rpc/v0/json_service.go             |  4 ---
 rpc/v0/wsService.go                |  4 ---
 15 files changed, 108 insertions(+), 114 deletions(-)

diff --git a/client/cmd/eris-client.go b/client/cmd/eris-client.go
index 57e8d3ba..b5082860 100644
--- a/client/cmd/eris-client.go
+++ b/client/cmd/eris-client.go
@@ -23,8 +23,6 @@ import (
 
 	"github.com/spf13/cobra"
 
-	log "github.com/eris-ltd/eris-logger"
-
 	"github.com/eris-ltd/eris-db/definitions"
 	"github.com/eris-ltd/eris-db/version"
 )
@@ -41,14 +39,6 @@ Made with <3 by Eris Industries.
 
 Complete documentation is available at https://monax.io/docs/documentation
 ` + "\nVERSION:\n " + version.VERSION,
-	PersistentPreRun: func(cmd *cobra.Command, args []string) {
-		log.SetLevel(log.WarnLevel)
-		if clientDo.Verbose {
-			log.SetLevel(log.InfoLevel)
-		} else if clientDo.Debug {
-			log.SetLevel(log.DebugLevel)
-		}
-	},
 	Run: func(cmd *cobra.Command, args []string) { cmd.Help() },
 }
 
diff --git a/cmd/serve.go b/cmd/serve.go
index f8b99c08..2c78c307 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -27,8 +27,8 @@ import (
 
 	"github.com/eris-ltd/eris-db/core"
 	"github.com/eris-ltd/eris-db/definitions"
+	"github.com/eris-ltd/eris-db/logging"
 	"github.com/eris-ltd/eris-db/logging/lifecycle"
-	"github.com/eris-ltd/eris-db/logging/structure"
 	"github.com/eris-ltd/eris-db/util"
 )
 
@@ -111,15 +111,13 @@ func NewCoreFromDo(do *definitions.Do) (*core.Core, error) {
 	}
 
 	// Create a root logger to pass through to dependencies
-	logger := lifecycle.NewLoggerFromConfig(*loggerConfig)
+	logger := logging.WithScope(lifecycle.NewServerLoggerFromConfig(*loggerConfig), "Serve")
 	// Capture all logging from tendermint/tendermint and tendermint/go-*
 	// dependencies
 	lifecycle.CaptureTendermintLog15Output(logger)
 	// And from stdlib go log
 	lifecycle.CaptureStdlibLogOutput(logger)
 
-	cmdLogger := logger.With("command", "serve")
-
 	// if do.ChainId is not yet set, load chain_id for assertion from configuration file
 
 	if do.ChainId == "" {
@@ -129,11 +127,11 @@ func NewCoreFromDo(do *definitions.Do) (*core.Core, error) {
 		}
 	}
 
-	cmdLogger.Info("chainId", do.ChainId,
+	logging.Msg(logger, "Loading configuration for serve command",
+		"chainId", do.ChainId,
 		"workingDirectory", do.WorkDir,
 		"dataDirectory", do.DataDir,
-		"genesisFile", do.GenesisFile,
-		structure.MessageKey, "Loading configuration for serve command")
+		"genesisFile", do.GenesisFile)
 
 	consensusConfig, err := core.LoadConsensusModuleConfig(do)
 	if err != nil {
@@ -145,9 +143,9 @@ func NewCoreFromDo(do *definitions.Do) (*core.Core, error) {
 		return nil, fmt.Errorf("Failed to load application manager module configuration: %s.", err)
 	}
 
-	cmdLogger.Info("consensusModule", consensusConfig.Version,
-		"applicationManager", managerConfig.Version,
-		structure.MessageKey, "Modules configured")
+	logging.Msg(logger, "Modules configured",
+		"consensusModule", consensusConfig.Version,
+		"applicationManager", managerConfig.Version)
 
 	return core.NewCore(do.ChainId, consensusConfig, managerConfig, logger)
 }
diff --git a/consensus/tendermint/tendermint.go b/consensus/tendermint/tendermint.go
index 545e4c1a..5adc08e1 100644
--- a/consensus/tendermint/tendermint.go
+++ b/consensus/tendermint/tendermint.go
@@ -34,13 +34,13 @@ import (
 	tmsp_types "github.com/tendermint/tmsp/types"
 
 	edb_event "github.com/eris-ltd/eris-db/event"
-	log "github.com/eris-ltd/eris-logger"
 
 	config "github.com/eris-ltd/eris-db/config"
 	manager_types "github.com/eris-ltd/eris-db/manager/types"
 	// files  "github.com/eris-ltd/eris-db/files"
 	blockchain_types "github.com/eris-ltd/eris-db/blockchain/types"
 	consensus_types "github.com/eris-ltd/eris-db/consensus/types"
+	"github.com/eris-ltd/eris-db/logging"
 	"github.com/eris-ltd/eris-db/logging/loggers"
 	"github.com/eris-ltd/eris-db/txs"
 	"github.com/tendermint/go-wire"
@@ -50,6 +50,7 @@ type Tendermint struct {
 	tmintNode   *node.Node
 	tmintConfig *TendermintConfig
 	chainId     string
+	logger      loggers.InfoTraceLogger
 }
 
 // Compiler checks to ensure Tendermint successfully implements
@@ -94,18 +95,19 @@ func NewTendermint(moduleConfig *config.ModuleConfig,
 	tmintConfig.AssertTendermintConsistency(moduleConfig,
 		privateValidatorFilePath)
 	chainId := tmintConfig.GetString("chain_id")
-	log.WithFields(log.Fields{
-		"chainId":              chainId,
-		"genesisFile":          tmintConfig.GetString("genesis_file"),
-		"nodeLocalAddress":     tmintConfig.GetString("node_laddr"),
-		"moniker":              tmintConfig.GetString("moniker"),
-		"seeds":                tmintConfig.GetString("seeds"),
-		"fastSync":             tmintConfig.GetBool("fast_sync"),
-		"rpcLocalAddress":      tmintConfig.GetString("rpc_laddr"),
-		"databaseDirectory":    tmintConfig.GetString("db_dir"),
-		"privateValidatorFile": tmintConfig.GetString("priv_validator_file"),
-		"privValFile":          moduleConfig.Config.GetString("private_validator_file"),
-	}).Debug("Loaded Tendermint sub-configuration")
+
+	logging.TraceMsg(logger, "Loaded Tendermint sub-configuration",
+		"chainId", chainId,
+		"genesisFile", tmintConfig.GetString("genesis_file"),
+		"nodeLocalAddress", tmintConfig.GetString("node_laddr"),
+		"moniker", tmintConfig.GetString("moniker"),
+		"seeds", tmintConfig.GetString("seeds"),
+		"fastSync", tmintConfig.GetBool("fast_sync"),
+		"rpcLocalAddress", tmintConfig.GetString("rpc_laddr"),
+		"databaseDirectory", tmintConfig.GetString("db_dir"),
+		"privateValidatorFile", tmintConfig.GetString("priv_validator_file"),
+		"privValFile", moduleConfig.Config.GetString("private_validator_file"))
+
 	// TODO: [ben] do not "or Generate Validator keys", rather fail directly
 	// TODO: [ben] implement the signer for Private validator over eris-keys
 	// TODO: [ben] copy from rootDir to tendermint workingDir;
@@ -118,8 +120,8 @@ func NewTendermint(moduleConfig *config.ModuleConfig,
 	// not running the tendermint RPC as it could lead to unexpected behaviour,
 	// not least if we accidentally try to run it on the same address as our own
 	if tmintConfig.GetString("rpc_laddr") != "" {
-		log.Warnf("Force disabling Tendermint's native RPC, which had been set to "+
-			"run on '%s' in the Tendermint config.", tmintConfig.GetString("rpc_laddr"))
+		logging.InfoMsg(logger, "Force disabling Tendermint's native RPC",
+			"provided_rpc_laddr", tmintConfig.GetString("rpc_laddr"))
 		tmintConfig.Set("rpc_laddr", "")
 	}
 
@@ -138,26 +140,25 @@ func NewTendermint(moduleConfig *config.ModuleConfig,
 		newNode.Stop()
 		return nil, fmt.Errorf("Failed to start Tendermint consensus node: %v", err)
 	}
-	log.WithFields(log.Fields{
-		"nodeAddress":       tmintConfig.GetString("node_laddr"),
-		"transportProtocol": "tcp",
-		"upnp":              !tmintConfig.GetBool("skip_upnp"),
-		"moniker":           tmintConfig.GetString("moniker"),
-	}).Info("Tendermint consensus node started")
+	logging.InfoMsg(logger, "Tendermint consensus node started",
+		"nodeAddress", tmintConfig.GetString("node_laddr"),
+		"transportProtocol", "tcp",
+		"upnp", !tmintConfig.GetBool("skip_upnp"),
+		"moniker", tmintConfig.GetString("moniker"))
 
 	// If seedNode is provided by config, dial out.
 	if tmintConfig.GetString("seeds") != "" {
 		seeds := strings.Split(tmintConfig.GetString("seeds"), ",")
 		newNode.DialSeeds(seeds)
-		log.WithFields(log.Fields{
-			"seeds": seeds,
-		}).Debug("Tendermint node called seeds")
+		logging.TraceMsg(logger, "Tendermint node called seeds",
+			"seeds", seeds)
 	}
 
 	return &Tendermint{
 		tmintNode:   newNode,
 		tmintConfig: tmintConfig,
 		chainId:     chainId,
+		logger:      logger,
 	}, nil
 }
 
@@ -230,7 +231,7 @@ func (tendermint *Tendermint) PublicValidatorKey() crypto.PubKey {
 }
 
 func (tendermint *Tendermint) Events() edb_event.EventEmitter {
-	return edb_event.NewEvents(tendermint.tmintNode.EventSwitch())
+	return edb_event.NewEvents(tendermint.tmintNode.EventSwitch(), tendermint.logger)
 }
 
 func (tendermint *Tendermint) BroadcastTransaction(transaction []byte,
diff --git a/core/core.go b/core/core.go
index 3bd32fdc..6c58d1a3 100644
--- a/core/core.go
+++ b/core/core.go
@@ -52,6 +52,7 @@ func NewCore(chainId string,
 	// start new event switch, TODO: [ben] replace with eris-db/event
 	evsw := events.NewEventSwitch()
 	evsw.Start()
+	logger = logging.WithScope(logger, "Core")
 
 	// start a new application pipe that will load an application manager
 	pipe, err := manager.NewApplicationPipe(managerConfig, evsw, logger,
diff --git a/event/event_cache.go b/event/event_cache.go
index 08db3011..3f230ae5 100644
--- a/event/event_cache.go
+++ b/event/event_cache.go
@@ -70,7 +70,7 @@ func reap(es *EventSubscriptions) {
 	defer es.mtx.Unlock()
 	for id, sub := range es.subs {
 		if time.Since(sub.ts) > reaperThreshold {
-			// Seems like Go is ok with this..
+			// Seems like Go is ok with evts..
 			delete(es.subs, id)
 			es.eventEmitter.Unsubscribe(id)
 		}
@@ -116,7 +116,7 @@ func (this *EventSubscriptions) Poll(subId string) ([]interface{}, error) {
 func (this *EventSubscriptions) Remove(subId string) error {
 	this.mtx.Lock()
 	defer this.mtx.Unlock()
-	// TODO Check this.
+	// TODO Check evts.
 	_, ok := this.subs[subId]
 	if !ok {
 		return fmt.Errorf("Subscription not active. ID: " + subId)
diff --git a/event/event_cache_test.go b/event/event_cache_test.go
index 35ce6d7e..0ac32fb2 100644
--- a/event/event_cache_test.go
+++ b/event/event_cache_test.go
@@ -131,7 +131,7 @@ func TestSubReaping(t *testing.T) {
 // Test that event subscriptions can be added and removed manually.
 func TestSubManualClose(t *testing.T) {
 	NUM_SUBS := 100
-	// Keep the reaper out of this.
+	// Keep the reaper out of evts.
 	reaperThreshold = 10000 * time.Millisecond
 	reaperTimeout = 10000 * time.Millisecond
 
@@ -178,7 +178,7 @@ func TestSubManualClose(t *testing.T) {
 // Test that the system doesn't fail under high pressure.
 func TestSubFlooding(t *testing.T) {
 	NUM_SUBS := 100
-	// Keep the reaper out of this.
+	// Keep the reaper out of evts.
 	reaperThreshold = 10000 * time.Millisecond
 	reaperTimeout = 10000 * time.Millisecond
 	// Crank it up. Now pressure is 10 times higher on each sub.
diff --git a/event/events.go b/event/events.go
index d5c37d8e..87647623 100644
--- a/event/events.go
+++ b/event/events.go
@@ -23,19 +23,20 @@ import (
 
 	"fmt"
 
+	"github.com/eris-ltd/eris-db/logging"
+	"github.com/eris-ltd/eris-db/logging/loggers"
 	"github.com/eris-ltd/eris-db/txs"
-	log "github.com/eris-ltd/eris-logger"
 	go_events "github.com/tendermint/go-events"
 	tm_types "github.com/tendermint/tendermint/types"
 )
 
-// TODO: [Silas] this is a compatibility layer between our event types and
+// TODO: [Silas] evts is a compatibility layer between our event types and
 // TODO: go-events. Our ultimate plan is to replace go-events with our own pub-sub
 // TODO: code that will better allow us to manage and multiplex events from different
 // TODO: subsystems
 
 // Oh for a sum type
-// We are using this as a marker interface for the
+// We are using evts as a marker interface for the
 type anyEventData interface{}
 
 type EventEmitter interface {
@@ -43,8 +44,8 @@ type EventEmitter interface {
 	Unsubscribe(subId string) error
 }
 
-func NewEvents(eventSwitch *go_events.EventSwitch) *events {
-	return &events{eventSwitch}
+func NewEvents(eventSwitch *go_events.EventSwitch, logger loggers.InfoTraceLogger) *events {
+	return &events{eventSwitch: eventSwitch, logger: logging.WithScope(logger, "Events")}
 }
 
 // Provides an EventEmitter that wraps many underlying EventEmitters as a
@@ -57,27 +58,28 @@ func Multiplex(events ...EventEmitter) *multiplexedEvents {
 // The events struct has methods for working with events.
 type events struct {
 	eventSwitch *go_events.EventSwitch
+	logger      loggers.InfoTraceLogger
 }
 
 // Subscribe to an event.
-func (this *events) Subscribe(subId, event string,
+func (evts *events) Subscribe(subId, event string,
 	callback func(txs.EventData)) error {
 	cb := func(evt go_events.EventData) {
 		eventData, err := mapToOurEventData(evt)
 		if err != nil {
-			log.WithError(err).
-				WithFields(log.Fields{"event": event}).
-				Error("Failed to map go-events EventData to our EventData")
+			logging.InfoMsg(evts.logger, "Failed to map go-events EventData to our EventData",
+				"error", err,
+				"event", event)
 		}
 		callback(eventData)
 	}
-	this.eventSwitch.AddListenerForEvent(subId, event, cb)
+	evts.eventSwitch.AddListenerForEvent(subId, event, cb)
 	return nil
 }
 
 // Un-subscribe from an event.
-func (this *events) Unsubscribe(subId string) error {
-	this.eventSwitch.RemoveListener(subId)
+func (evts *events) Unsubscribe(subId string) error {
+	evts.eventSwitch.RemoveListener(subId)
 	return nil
 }
 
@@ -142,7 +144,7 @@ func GenerateSubId() (string, error) {
 }
 
 func mapToOurEventData(eventData anyEventData) (txs.EventData, error) {
-	// TODO: [Silas] avoid this with a better event pub-sub system of our own
+	// TODO: [Silas] avoid evts with a better event pub-sub system of our own
 	// TODO: that maybe involves a registry of events
 	switch eventData := eventData.(type) {
 	case txs.EventData:
diff --git a/logging/convention.go b/logging/convention.go
index 3c75270a..ec833b96 100644
--- a/logging/convention.go
+++ b/logging/convention.go
@@ -31,12 +31,22 @@ func TraceMsg(logger loggers.InfoTraceLogger, message string, keyvals ...interfa
 	Msg(kitlog.LoggerFunc(logger.Trace), message, keyvals...)
 }
 
+// Establish or extend the scope of this logger by appending scopeName to the Scope vector.
+// Like With the logging scope is append only but can be used to provide parenthetical scopes by hanging on to the
+// parent scope and using once the scope has been exited. The scope mechanism does is agnostic to the type of scope
+// so can be used to identify certain segments of the call stack, a lexical scope, or any other nested scope.
+func WithScope(logger loggers.InfoTraceLogger, scopeName string) loggers.InfoTraceLogger {
+	// InfoTraceLogger will collapse successive (ScopeKey, scopeName) pairs into a vector in the order which they appear
+	return logger.With(structure.ScopeKey, scopeName)
+}
+
 // Record a structured log line with a message
 func Msg(logger kitlog.Logger, message string, keyvals ...interface{}) error {
 	prepended := slice.CopyPrepend(keyvals, structure.MessageKey, message)
 	return logger.Log(prepended...)
 }
 
+
 // Record a structured log line with a message and conventional keys
 func MsgVals(logger kitlog.Logger, message string, vals ...interface{}) error {
 	keyvals := make([]interface{}, len(vals)*2)
diff --git a/logging/lifecycle/lifecycle.go b/logging/lifecycle/lifecycle.go
index 4468e54b..1a9608fa 100644
--- a/logging/lifecycle/lifecycle.go
+++ b/logging/lifecycle/lifecycle.go
@@ -16,7 +16,15 @@ import (
 	"time"
 )
 
-func NewLoggerFromConfig(LoggingConfig logging.LoggingConfig) loggers.InfoTraceLogger {
+// Obtain a default eris-client logger from config
+func NewClientLoggerFromConfig(LoggingConfig logging.LoggingConfig) loggers.InfoTraceLogger {
+	infoLogger := kitlog.NewLogfmtLogger(os.Stderr)
+	traceLogger := kitlog.NewLogfmtLogger(os.Stderr)
+	return logging.WithMetadata(loggers.NewInfoTraceLogger(infoLogger, traceLogger))
+}
+
+// Obtain a default eris-server (eris-db serve ...) logger
+func NewServerLoggerFromConfig(LoggingConfig logging.LoggingConfig) loggers.InfoTraceLogger {
 	infoLogger := kitlog.NewLogfmtLogger(os.Stderr)
 	traceLogger := kitlog.NewLogfmtLogger(os.Stderr)
 	return logging.WithMetadata(loggers.NewInfoTraceLogger(infoLogger, traceLogger))
diff --git a/logging/structure/structure.go b/logging/structure/structure.go
index 976332be..8a81777a 100644
--- a/logging/structure/structure.go
+++ b/logging/structure/structure.go
@@ -70,6 +70,8 @@ type vectorValueindex struct {
 // The result is a copy of keyvals where the first occurrence of each matching key and its first value are replaced by
 // that key and all of its values in a single slice.
 func Vectorise(keyvals []interface{}, vectorKeys ...string) []interface{} {
+	// We rely on working against a single backing array, so we use a capacity that is the maximum possible size of the
+	// slice after vectorising (in the case there are no duplicate keys and this is a no-op)
 	outputKeyvals := make([]interface{}, 0, len(keyvals))
 	// Track the location and vector status of the values in the output
 	valueIndices := make(map[string]*vectorValueindex, len(vectorKeys))
diff --git a/manager/eris-mint/eris-mint.go b/manager/eris-mint/eris-mint.go
index 2c08757c..6a79b82e 100644
--- a/manager/eris-mint/eris-mint.go
+++ b/manager/eris-mint/eris-mint.go
@@ -25,8 +25,8 @@ import (
 	wire "github.com/tendermint/go-wire"
 	tmsp "github.com/tendermint/tmsp/types"
 
-	log "github.com/eris-ltd/eris-logger"
-
+	"github.com/eris-ltd/eris-db/logging"
+	"github.com/eris-ltd/eris-db/logging/loggers"
 	sm "github.com/eris-ltd/eris-db/manager/eris-mint/state"
 	manager_types "github.com/eris-ltd/eris-db/manager/types"
 	"github.com/eris-ltd/eris-db/txs"
@@ -47,7 +47,8 @@ type ErisMint struct {
 	evc  *tendermint_events.EventCache
 	evsw *tendermint_events.EventSwitch
 
-	nTxs int // count txs in a block
+	nTxs   int // count txs in a block
+	logger loggers.InfoTraceLogger
 }
 
 // NOTE [ben] Compiler check to ensure ErisMint successfully implements
@@ -71,13 +72,14 @@ func (app *ErisMint) GetCheckCache() *sm.BlockCache {
 	return app.checkCache
 }
 
-func NewErisMint(s *sm.State, evsw *tendermint_events.EventSwitch) *ErisMint {
+func NewErisMint(s *sm.State, evsw *tendermint_events.EventSwitch, logger loggers.InfoTraceLogger) *ErisMint {
 	return &ErisMint{
 		state:      s,
 		cache:      sm.NewBlockCache(s),
 		checkCache: sm.NewBlockCache(s),
 		evc:        tendermint_events.NewEventCache(evsw),
 		evsw:       evsw,
+		logger:     logging.WithScope(logger, "ErisMint"),
 	}
 }
 
@@ -145,18 +147,17 @@ func (app *ErisMint) Commit() (res tmsp.Result) {
 	defer app.mtx.Unlock()
 
 	app.state.LastBlockHeight += 1
-	log.WithFields(log.Fields{
-		"blockheight": app.state.LastBlockHeight,
-	}).Info("Commit block")
+	logging.InfoMsg(app.logger, "Committing block",
+		"last_block_height", app.state.LastBlockHeight)
 
 	// sync the AppendTx cache
 	app.cache.Sync()
 
 	// Refresh the checkCache with the latest commited state
-	log.WithFields(log.Fields{
-		"txs": app.nTxs,
-	}).Info("Reset checkCache")
+	logging.InfoMsg(app.logger, "Resetting checkCache",
+		"txs", app.nTxs)
 	app.checkCache = sm.NewBlockCache(app.state)
+
 	app.nTxs = 0
 
 	// save state to disk
diff --git a/manager/eris-mint/pipe.go b/manager/eris-mint/pipe.go
index d9691f27..121f9fa4 100644
--- a/manager/eris-mint/pipe.go
+++ b/manager/eris-mint/pipe.go
@@ -36,15 +36,14 @@ import (
 	core_types "github.com/eris-ltd/eris-db/core/types"
 	"github.com/eris-ltd/eris-db/definitions"
 	edb_event "github.com/eris-ltd/eris-db/event"
+	"github.com/eris-ltd/eris-db/logging"
 	"github.com/eris-ltd/eris-db/logging/loggers"
-	"github.com/eris-ltd/eris-db/logging/structure"
 	vm "github.com/eris-ltd/eris-db/manager/eris-mint/evm"
 	"github.com/eris-ltd/eris-db/manager/eris-mint/state"
 	state_types "github.com/eris-ltd/eris-db/manager/eris-mint/state/types"
 	manager_types "github.com/eris-ltd/eris-db/manager/types"
 	rpc_tm_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types"
 	"github.com/eris-ltd/eris-db/txs"
-	log "github.com/eris-ltd/eris-logger"
 )
 
 type erisMintPipe struct {
@@ -81,17 +80,17 @@ func NewErisMintPipe(moduleConfig *config.ModuleConfig,
 	if err != nil {
 		return nil, fmt.Errorf("Failed to start state: %v", err)
 	}
+	logger = logging.WithScope(logger, "ErisMintPipe")
 	// assert ChainId matches genesis ChainId
-	logger.Info(
+	logging.InfoMsg(logger, "Loaded state",
 		"chainId", startedState.ChainID,
 		"lastBlockHeight", startedState.LastBlockHeight,
-		"lastBlockHash", startedState.LastBlockHash,
-		structure.MessageKey, "Loaded state")
+		"lastBlockHash", startedState.LastBlockHash)
 	// start the application
-	erisMint := NewErisMint(startedState, eventSwitch)
+	erisMint := NewErisMint(startedState, eventSwitch, logger)
 
 	// initialise the components of the pipe
-	events := edb_event.NewEvents(eventSwitch)
+	events := edb_event.NewEvents(eventSwitch, logger)
 	accounts := newAccounts(erisMint)
 	namereg := newNameReg(erisMint)
 
@@ -172,12 +171,8 @@ func startState(dataDir, backend, genesisFile, chainId string) (*state.State,
 		}
 		// assert loaded genesis doc has the same chainId as the provided chainId
 		if genesisDoc.ChainID != chainId {
-			log.WithFields(log.Fields{
-				"chainId from loaded genesis": genesisDoc.ChainID,
-				"chainId from configuration":  chainId,
-			}).Warn("Conflicting chainIds")
-			// return nil, nil, fmt.Errorf("ChainId (%s) loaded from genesis document in existing database does not match configuration chainId (%s).",
-			// genesisDoc.ChainID, chainId)
+			return nil, nil, fmt.Errorf("ChainId (%s) loaded from genesis document in existing database does not match"+
+				" configuration chainId (%s).", genesisDoc.ChainID, chainId)
 		}
 	}
 
@@ -261,11 +256,9 @@ func (pipe *erisMintPipe) Subscribe(event string,
 	subscriptionId, err := edb_event.GenerateSubId()
 	if err != nil {
 		return nil, err
+		logging.InfoMsg(pipe.logger, "Subscribing to event",
+			"event", event, "subscriptionId", subscriptionId)
 	}
-
-	log.WithFields(log.Fields{"event": event, "subscriptionId": subscriptionId}).
-		Info("Subscribing to event")
-
 	pipe.consensusAndManagerEvents().Subscribe(subscriptionId, event,
 		func(eventData txs.EventData) {
 			result := rpc_tm_types.ErisDBResult(&rpc_tm_types.ResultEvent{event,
@@ -280,8 +273,8 @@ func (pipe *erisMintPipe) Subscribe(event string,
 }
 
 func (pipe *erisMintPipe) Unsubscribe(subscriptionId string) (*rpc_tm_types.ResultUnsubscribe, error) {
-	log.WithFields(log.Fields{"subscriptionId": subscriptionId}).
-		Info("Unsubscribing from event")
+	logging.InfoMsg(pipe.logger, "Unsubscribing from event",
+		"subscriptionId", subscriptionId)
 	pipe.consensusAndManagerEvents().Unsubscribe(subscriptionId)
 	return &rpc_tm_types.ResultUnsubscribe{SubscriptionId: subscriptionId}, nil
 }
@@ -359,13 +352,8 @@ func (pipe *erisMintPipe) Genesis() (*rpc_tm_types.ResultGenesis, error) {
 func (pipe *erisMintPipe) GetAccount(address []byte) (*rpc_tm_types.ResultGetAccount,
 	error) {
 	cache := pipe.erisMint.GetCheckCache()
-	// cache := mempoolReactor.Mempool.GetCache()
 	account := cache.GetAccount(address)
-	if account == nil {
-		log.Warn("Nil Account")
-		return &rpc_tm_types.ResultGetAccount{nil}, nil
-	}
-	return &rpc_tm_types.ResultGetAccount{account}, nil
+	return &rpc_tm_types.ResultGetAccount{Account: account}, nil
 }
 
 func (pipe *erisMintPipe) ListAccounts() (*rpc_tm_types.ResultListAccounts, error) {
@@ -597,10 +585,11 @@ func (pipe *erisMintPipe) BroadcastTxSync(tx txs.Tx) (*rpc_tm_types.ResultBroadc
 	case tmsp_types.CodeType_InternalError:
 		return resultBroadCastTx, fmt.Errorf(resultBroadCastTx.Log)
 	default:
-		log.WithFields(log.Fields{
-			"application":    GetErisMintVersion().GetVersionString(),
-			"TMSP_code_type": responseCheckTx.Code,
-		}).Warn("Unknown error returned from Tendermint CheckTx on BroadcastTxSync")
+		logging.InfoMsg(pipe.logger, "Unknown error returned from Tendermint CheckTx on BroadcastTxSync",
+			"application", GetErisMintVersion().GetVersionString(),
+			"TMSP_code_type", responseCheckTx.Code,
+			"TMSP_log", responseCheckTx.Log,
+		)
 		return resultBroadCastTx, fmt.Errorf("Unknown error returned: " + responseCheckTx.Log)
 	}
 }
diff --git a/manager/manager.go b/manager/manager.go
index 276d872f..6f71aefa 100644
--- a/manager/manager.go
+++ b/manager/manager.go
@@ -26,8 +26,8 @@ import (
 	erismint "github.com/eris-ltd/eris-db/manager/eris-mint"
 	// types       "github.com/eris-ltd/eris-db/manager/types"
 
+	"github.com/eris-ltd/eris-db/logging"
 	"github.com/eris-ltd/eris-db/logging/loggers"
-	"github.com/eris-ltd/eris-db/logging/structure"
 )
 
 // NewApplicationPipe returns an initialised Pipe interface
@@ -44,9 +44,9 @@ func NewApplicationPipe(moduleConfig *config.ModuleConfig,
 		if err := erismint.AssertCompatibleConsensus(consensusMinorVersion); err != nil {
 			return nil, err
 		}
-		logger.Info("compatibleConsensus", consensusMinorVersion,
-			"erisMintVersion", erismint.GetErisMintVersion().GetVersionString(),
-			structure.MessageKey, "Loading ErisMint")
+		logging.InfoMsg(logger, "Loading ErisMint",
+			"compatibleConsensus", consensusMinorVersion,
+			"erisMintVersion", erismint.GetErisMintVersion().GetVersionString())
 		return erismint.NewErisMintPipe(moduleConfig, evsw, logger)
 	}
 	return nil, fmt.Errorf("Failed to return Pipe for %s", moduleConfig.Name)
diff --git a/rpc/v0/json_service.go b/rpc/v0/json_service.go
index 4c43f533..ab4ce33f 100644
--- a/rpc/v0/json_service.go
+++ b/rpc/v0/json_service.go
@@ -6,8 +6,6 @@ import (
 
 	"github.com/gin-gonic/gin"
 
-	log "github.com/eris-ltd/eris-logger"
-
 	definitions "github.com/eris-ltd/eris-db/definitions"
 	event "github.com/eris-ltd/eris-db/event"
 	rpc "github.com/eris-ltd/eris-db/rpc"
@@ -125,10 +123,8 @@ func (this *ErisDbJsonService) writeError(msg, id string, code int, w http.Respo
 
 // Helper for writing responses.
 func (this *ErisDbJsonService) writeResponse(id string, result interface{}, w http.ResponseWriter) {
-	log.Debug("Result: %v\n", result)
 	response := rpc.NewRPCResponse(id, result)
 	err := this.codec.Encode(response, w)
-	log.Debug("Response: %v\n", response)
 	if err != nil {
 		this.writeError("Internal error: "+err.Error(), id, rpc.INTERNAL_ERROR, w)
 		return
diff --git a/rpc/v0/wsService.go b/rpc/v0/wsService.go
index 35705ed3..c7e89ff5 100644
--- a/rpc/v0/wsService.go
+++ b/rpc/v0/wsService.go
@@ -4,8 +4,6 @@ import (
 	"encoding/json"
 	"fmt"
 
-	log "github.com/eris-ltd/eris-logger"
-
 	definitions "github.com/eris-ltd/eris-db/definitions"
 	"github.com/eris-ltd/eris-db/event"
 	rpc "github.com/eris-ltd/eris-db/rpc"
@@ -36,7 +34,6 @@ func NewErisDbWsService(codec rpc.Codec,
 
 // Process a request.
 func (this *ErisDbWsService) Process(msg []byte, session *server.WSSession) {
-	log.Debug("REQUEST: %s\n", string(msg))
 	// Create new request object and unmarshal.
 	req := &rpc.RPCRequest{}
 	errU := json.Unmarshal(msg, req)
@@ -84,7 +81,6 @@ func (this *ErisDbWsService) writeResponse(id string, result interface{},
 	session *server.WSSession) error {
 	response := rpc.NewRPCResponse(id, result)
 	bts, err := this.codec.EncodeBytes(response)
-	log.Debug("RESPONSE: %v\n", response)
 	if err != nil {
 		this.writeError("Internal error: "+err.Error(), id, rpc.INTERNAL_ERROR, session)
 		return err
-- 
GitLab