-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
45 lines (37 loc) · 1.34 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package pgx
// 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
// to adapt any logger to this interface.
type Logger interface {
// Log a message at the given level with context key/value pairs
Debug(msg string, ctx ...interface{})
Info(msg string, ctx ...interface{})
Warn(msg string, ctx ...interface{})
Error(msg string, ctx ...interface{})
}
type discardLogger struct{}
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
}
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...)
}