forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Silas Davis
committed
Dec 20, 2016
1 parent
4f0b5fb
commit 01bf0c4
Showing
15 changed files
with
219 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package logging | ||
|
||
import ( | ||
"github.com/eris-ltd/eris-db/logging/loggers" | ||
"github.com/eris-ltd/eris-db/logging/structure" | ||
"github.com/eris-ltd/eris-db/util/slice" | ||
kitlog "github.com/go-kit/kit/log" | ||
) | ||
|
||
// Helper functions for InfoTraceLoggers, sort of extension methods to loggers | ||
// to centralise and establish logging conventions on top of in with the base | ||
// logging interface | ||
|
||
// Record structured Info log line with a message and conventional keys | ||
func InfoMsgVals(logger loggers.InfoTraceLogger, message string, vals ...interface{}) { | ||
MsgVals(kitlog.LoggerFunc(logger.Info), message, vals...) | ||
} | ||
|
||
// Record structured Trace log line with a message and conventional keys | ||
func TraceMsgVals(logger loggers.InfoTraceLogger, message string, vals ...interface{}) { | ||
MsgVals(kitlog.LoggerFunc(logger.Trace), message, vals...) | ||
} | ||
|
||
// Record structured Info log line with a message | ||
func InfoMsg(logger loggers.InfoTraceLogger, message string, keyvals ...interface{}) { | ||
Msg(kitlog.LoggerFunc(logger.Info), message, keyvals...) | ||
} | ||
|
||
// Record structured Trace log line with a message | ||
func TraceMsg(logger loggers.InfoTraceLogger, message string, keyvals ...interface{}) { | ||
Msg(kitlog.LoggerFunc(logger.Trace), message, keyvals...) | ||
} | ||
|
||
func WithScope(logger loggers.InfoTraceLogger, scopes... string) loggers.InfoTraceLogger { | ||
return logger.With() | ||
} | ||
|
||
// Record a structured log line with a message | ||
func Msg(logger kitlog.Logger, message string, keyvals ...interface{}) error { | ||
return logger.Log(slice.CopyPrepend(keyvals, structure.MessageKey, message)) | ||
} | ||
|
||
// 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) | ||
for i := 0; i < len(vals); i++ { | ||
kv := i * 2 | ||
keyvals[kv] = structure.KeyFromValue(vals[i]) | ||
keyvals[kv+1] = vals[i] | ||
} | ||
return Msg(logger, message, keyvals) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package loggers | ||
|
||
import ( | ||
"github.com/eris-ltd/eris-db/logging/structure" | ||
kitlog "github.com/go-kit/kit/log" | ||
) | ||
|
||
// Treat duplicate keys | ||
type vectorValuedLogger struct { | ||
logger kitlog.Logger | ||
} | ||
|
||
var _ kitlog.Logger = &vectorValuedLogger{} | ||
|
||
func (vvl *vectorValuedLogger) Log(keyvals ...interface{}) error { | ||
keys, vals := structure.KeyValuesVector(keyvals) | ||
kvs := make([]interface{}, len(keys)*2) | ||
for i := 0; i < len(keys); i++ { | ||
kv := i * 2 | ||
key := keys[i] | ||
kvs[kv] = key | ||
kvs[kv+1] = vals[key] | ||
} | ||
return vvl.logger.Log(kvs...) | ||
} | ||
|
||
func VectorValuedLogger(logger kitlog.Logger) *vectorValuedLogger { | ||
return &vectorValuedLogger{logger: logger} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package loggers | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/eris-ltd/eris-db/util/slice" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestVectorValuedLogger(t *testing.T) { | ||
logger := newTestLogger() | ||
vvl := VectorValuedLogger(logger) | ||
vvl.Log("foo", "bar", "seen", 1, "seen", 3, "seen", 2) | ||
|
||
assert.Equal(t, Slice("foo", "bar", "seen", Slice(1, 3, 2)), | ||
logger.logLines[0]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.