logger/logger.go

44 lines
862 B
Go
Raw Normal View History

2021-08-09 03:49:23 +00:00
package logger
import (
"go.elastic.co/apm/module/apmzap"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type (
2022-08-24 03:28:30 +00:00
LogData struct {
2022-08-23 09:10:31 +00:00
Source string
Message string
Data interface{}
}
2022-08-24 03:27:15 +00:00
Map map[string]interface{}
2021-08-09 03:49:23 +00:00
)
var (
zapLogger *zap.Logger
err error
)
// Init ...
func Init(appName, server string) {
cfg := zap.Config{
2022-08-23 09:10:31 +00:00
Encoding: "console",
2021-08-09 03:49:23 +00:00
Level: zap.NewAtomicLevelAt(zapcore.DebugLevel),
OutputPaths: []string{"stdout"},
InitialFields: map[string]interface{}{"server": server, "capture": appName},
EncoderConfig: zapcore.EncoderConfig{
MessageKey: "message",
LevelKey: "level",
EncodeLevel: zapcore.CapitalLevelEncoder,
TimeKey: "time",
EncodeTime: zapcore.ISO8601TimeEncoder,
},
}
zapLogger, err = cfg.Build(zap.WrapCore((&apmzap.Core{}).WrapCore))
if err != nil {
panic(err)
}
}