-
Notifications
You must be signed in to change notification settings - Fork 12
/
log.go
52 lines (42 loc) · 1.28 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
package fuego
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// Logger exposes basic logging methods.
// This is provided as a sheer convenience.
type Logger interface {
Debug(msg string, fields ...zap.Field)
Info(msg string, fields ...zap.Field)
Warn(msg string, fields ...zap.Field)
Error(msg string, fields ...zap.Field)
With(fields ...zap.Field) *zap.Logger
}
// init initialises zap's global loggers (i.e. zap.L() and zap.S().
// Log level is retrieved from environment variable LOB_LEVEL, defaulting to "info" otherwise.
// To activate this facility, add a blank import to this package.
// nolint: gochecknoinits
func init() {
level := os.Getenv("FUEGO_LOG_LEVEL")
if level == "" {
level = "error"
}
initialiseZapGlobals(level)
}
// Option is a function to provide the Logger creation with extra initialisation options.
type Option func(*zap.Config)
func initialiseZapGlobals(level string) {
zapLevel := zap.InfoLevel
_ = zapLevel.UnmarshalText([]byte(level))
lc := zap.NewProductionConfig()
lc.Level = zap.NewAtomicLevelAt(zapLevel)
lc.OutputPaths = []string{"stdout"}
lc.ErrorOutputPaths = []string{"stderr"}
lc.EncoderConfig.EncodeTime = zapcore.RFC3339NanoTimeEncoder
logger, err := lc.Build()
if err != nil {
panic(err)
}
zap.ReplaceGlobals(logger)
}