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 (
|
|
|
|
// LogData for tracking
|
2022-08-23 09:10:31 +00:00
|
|
|
LogData struct {
|
|
|
|
Source string
|
|
|
|
Message string
|
|
|
|
Data 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)
|
|
|
|
}
|
|
|
|
}
|