-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
33 lines (26 loc) · 818 Bytes
/
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
// Package logger provides a convenience function to constructing a logger
// for use. This is required not just for applications but for testing.
package logger
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// New constructs a Sugared Logger that writes to stdout and
// provides human-readable timestamps.
func New(service string, outputPaths ...string) (*zap.SugaredLogger, error) {
config := zap.NewProductionConfig()
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
config.DisableStacktrace = true
config.InitialFields = map[string]any{
"service": service,
}
config.OutputPaths = []string{"stdout"}
if outputPaths != nil {
config.OutputPaths = outputPaths
}
log, err := config.Build(zap.WithCaller(true))
if err != nil {
return nil, err
}
return log.Sugar(), nil
}