You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/config"
|
|
"joybuywork/internal/consts"
|
|
"fmt"
|
|
"gits.branchcn.com/backend/microcode/plugins/logger"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
var Logger logger.Plugin
|
|
|
|
func InitLogger() {
|
|
loggerConfig := logger.PluginConfig{
|
|
ModeProd: config.Config.Server.Env == "prod",
|
|
Level: zapcore.InfoLevel,
|
|
StdOut: config.Config.Logger.StdOut,
|
|
FileOut: config.Config.Logger.FileOut,
|
|
JsonEncode: false,
|
|
StackTraceLevel: zapcore.ErrorLevel,
|
|
FileConfig: logger.FileConfig{
|
|
Path: config.Config.Logger.Path,
|
|
MaxSize: config.Config.Logger.MaxSize,
|
|
MaxBackups: config.Config.Logger.MaxBackups,
|
|
MaxAge: config.Config.Logger.MaxAge,
|
|
LocalTime: true,
|
|
Compress: config.Config.Logger.Compress,
|
|
},
|
|
AlarmWriter: FeiShu.Alert,
|
|
Env: config.Config.Server.Env,
|
|
ContextTraceKey: consts.TraceIdKey,
|
|
ContextKey: []string{consts.CtxReqId, consts.CtxBootId, consts.CtxMsgId},
|
|
}
|
|
Logger = logger.NewPlugin(loggerConfig)
|
|
|
|
}
|
|
|
|
func TryCatch(ctx context.Context, msg string) {
|
|
if err := recover(); err != nil {
|
|
Logger.Error(ctx, fmt.Sprintf("%s, 错误信息:%v", msg, err))
|
|
}
|
|
}
|