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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user