-
Notifications
You must be signed in to change notification settings - Fork 568
/
log.go
56 lines (47 loc) · 2.02 KB
/
log.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
46
47
48
49
50
51
52
53
54
55
56
package log
import (
"context"
"io"
"go.uber.org/zap"
"go.uber.org/zap/zapio"
)
// Field is a typed log field. It is lazily evaluated at log marshaling time.
type Field = zap.Field
// Debug logs a message, with fields, at level DEBUG. Level debug is appropriate for messages that
// are interesting to Pachyderm developers, but not operators or users; or logs that are generated
// by internal action at a rate of more than 1 message per second.
//
// Most tracing and background operations are DEBUG logs.
func Debug(ctx context.Context, msg string, fields ...Field) {
extractLogger(ctx).Debug(msg, fields...)
}
// Info logs a message, with fields, at level INFO. Level info is appropriate for messages that are
// interesting to operators of Pachyderm (like information about applying configuration changes), or
// that represent user action (like incoming RPC requests).
//
// Most warnings and user-caused errors are INFO logs.
func Info(ctx context.Context, msg string, fields ...Field) {
extractLogger(ctx).Info(msg, fields...)
}
// Error logs a message, with fields, at level ERROR. Level error is appropriate for messages that
// indicate a malfunction that an operator of Pachyderm can repair.
func Error(ctx context.Context, msg string, fields ...Field) {
extractLogger(ctx).Error(msg, fields...)
}
// DPanic is a message that panics in development, but is only logged in production.
func DPanic(ctx context.Context, msg string, fields ...Field) {
extractLogger(ctx).DPanic(msg, fields...)
}
// Exit logs a message, with fields, at level FATAL and then exits with status 1. Level fatal is
// only appropriate for use in interactive scripts.
func Exit(ctx context.Context, msg string, fields ...Field) {
extractLogger(ctx).Fatal(msg, fields...)
}
// WriterAt creates a new io.Writer that logs each line as a log message at the provided levels.
func WriterAt(ctx context.Context, lvl Level) io.WriteCloser {
l := extractLogger(ctx).WithOptions(zap.WithCaller(false))
return &zapio.Writer{
Log: l,
Level: lvl.coreLevel(),
}
}