2
0

Add SetLogger to *Conn

Allow replacing logger after connection is established. Also
refactor internals of logging such that there is a log method that
adds the pid to all log calls instead of making a new logger object.
The reason for this is so pid will be logged regardless of whether
loggers are replaced and restored.
This commit is contained in:
Jack Christensen
2016-02-12 17:49:04 -06:00
parent beed0c0e5f
commit cffae7ff5d
5 changed files with 95 additions and 68 deletions
-25
View File
@@ -30,31 +30,6 @@ type Logger interface {
Error(msg string, ctx ...interface{})
}
type connLogger struct {
logger Logger
pid int32
}
func (l *connLogger) Debug(msg string, ctx ...interface{}) {
ctx = append(ctx, "pid", l.pid)
l.logger.Debug(msg, ctx...)
}
func (l *connLogger) Info(msg string, ctx ...interface{}) {
ctx = append(ctx, "pid", l.pid)
l.logger.Info(msg, ctx...)
}
func (l *connLogger) Warn(msg string, ctx ...interface{}) {
ctx = append(ctx, "pid", l.pid)
l.logger.Warn(msg, ctx...)
}
func (l *connLogger) Error(msg string, ctx ...interface{}) {
ctx = append(ctx, "pid", l.pid)
l.logger.Error(msg, ctx...)
}
// Converts log level string to constant
//
// Valid levels: