2
0

More efficient logging with log levels

This commit is contained in:
Jack Christensen
2015-09-16 08:20:51 -05:00
parent a2e078597b
commit a1aa06c934
4 changed files with 77 additions and 41 deletions
+12 -10
View File
@@ -5,6 +5,18 @@ import (
"fmt"
)
// The values for log levels are chosen such that the zero value means that no
// log level was specified and we can default to LogLevelDebug to preserve
// the behavior that existed prior to log level introduction.
const (
LogLevelTrace = 6
LogLevelDebug = 5
LogLevelInfo = 4
LogLevelWarn = 3
LogLevelError = 2
LogLevelNone = 1
)
// Logger is the interface used to get logging from pgx internals.
// https://github.com/inconshreveable/log15 is the recommended logging package.
// This logging interface was extracted from there. However, it should be simple
@@ -17,16 +29,6 @@ type Logger interface {
Error(msg string, ctx ...interface{})
}
type discardLogger struct{}
// default discardLogger instance
var dlogger = &discardLogger{}
func (l *discardLogger) Debug(msg string, ctx ...interface{}) {}
func (l *discardLogger) Info(msg string, ctx ...interface{}) {}
func (l *discardLogger) Warn(msg string, ctx ...interface{}) {}
func (l *discardLogger) Error(msg string, ctx ...interface{}) {}
type connLogger struct {
logger Logger
pid int32