/
option.go
53 lines (46 loc) · 1.33 KB
/
option.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
package otelzap
import "go.uber.org/zap/zapcore"
// Option applies a configuration to the given config.
type Option func(l *Logger)
// WithMinLevel sets the minimal zap logging level on which the log message
// is recorded on the span.
//
// The default is >= zap.WarnLevel.
func WithMinLevel(lvl zapcore.Level) Option {
return func(l *Logger) {
l.minLevel = lvl
}
}
// WithErrorStatusLevel sets the minimal zap logging level on which
// the span status is set to codes.Error.
//
// The default is >= zap.ErrorLevel.
func WithErrorStatusLevel(lvl zapcore.Level) Option {
return func(l *Logger) {
l.errorStatusLevel = lvl
}
}
// WithCaller configures the logger to annotate each event with the filename,
// line number, and function name of the caller.
//
// It is enabled by default.
func WithCaller(on bool) Option {
return func(l *Logger) {
l.caller = on
}
}
// WithStackTrace configures the logger to capture logs with a stack trace.
func WithStackTrace(on bool) Option {
return func(l *Logger) {
l.stackTrace = on
}
}
// WithTraceID configures the logger to add `trace_id` field to structured log messages.
//
// This option is only useful with backends that don't support OTLP and instead parse log
// messages to extract structured information.
func WithTraceIDField(on bool) Option {
return func(l *Logger) {
l.withTraceID = on
}
}