-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
39 lines (31 loc) · 791 Bytes
/
config.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
package zap
import (
"time"
"github.com/alexfalkowski/go-service/env"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// Config for zap.
type Config struct {
Level string `yaml:"level" json:"level" toml:"level"`
}
// NewConfig for zap.
func NewConfig(env env.Environment, config *Config) (zap.Config, error) {
l, err := zap.ParseAtomicLevel(config.Level)
if err != nil {
return zap.Config{}, err
}
cfg := zap.NewProductionConfig()
if env.IsDevelopment() {
cfg.Encoding = "json"
cfg.Sampling = nil
cfg.Development = true
}
cfg.Level = l
cfg.DisableCaller = true
cfg.DisableStacktrace = true
cfg.EncoderConfig.EncodeTime = zapcore.TimeEncoder(func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format(time.RFC3339))
})
return cfg, nil
}