完成日志写入zinc的能力
This commit is contained in:
46
config.go
46
config.go
@ -9,7 +9,6 @@ package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -223,18 +222,19 @@ func defaultEncodeDuration(d time.Duration, enc zapcore.PrimitiveArrayEncoder) {
|
||||
//
|
||||
// Date : 11:41 下午 2021/1/2
|
||||
type OptionLogger struct {
|
||||
UseJsonFormat bool // 日志使用json格式
|
||||
MessageKey string // message 字段
|
||||
LevelKey string // level 字段
|
||||
TimeKey string // 时间字段
|
||||
CallerKey string // 记录日志的文件的代码行数
|
||||
UseShortCaller bool // 使用短的调用文件格式
|
||||
TimeEncoder zapcore.TimeEncoder // 格式化时间的函数
|
||||
EncodeDuration zapcore.DurationEncoder // 原始时间信息
|
||||
WithCaller bool // 是否打印文件行号
|
||||
WithCallerSkip int // 跳过的调用数
|
||||
ConsoleOutput bool // 控制台输出
|
||||
Encoder zapcore.Encoder // 编码函数
|
||||
UseJsonFormat bool // 日志使用json格式
|
||||
MessageKey string // message 字段
|
||||
LevelKey string // level 字段
|
||||
TimeKey string // 时间字段
|
||||
CallerKey string // 记录日志的文件的代码行数
|
||||
UseShortCaller bool // 使用短的调用文件格式
|
||||
TimeEncoder zapcore.TimeEncoder // 格式化时间的函数
|
||||
EncodeDuration zapcore.DurationEncoder // 原始时间信息
|
||||
WithCaller bool // 是否打印文件行号
|
||||
WithCallerSkip int // 跳过的调用数
|
||||
ConsoleOutput bool // 控制台输出
|
||||
Encoder zapcore.Encoder // 编码函数
|
||||
ZincCollectConfig *ZincConfig // zinc采集配置
|
||||
}
|
||||
|
||||
// SetLoggerOptionFunc 设置日志配置
|
||||
@ -378,6 +378,13 @@ func WithEncodeDuration(encoder zapcore.DurationEncoder) SetLoggerOptionFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// WithZincLogCollect zinc日志采集
|
||||
func WithZincLogCollect(zincCfg *ZincConfig) SetLoggerOptionFunc {
|
||||
return func(o *OptionLogger) {
|
||||
o.ZincCollectConfig = zincCfg
|
||||
}
|
||||
}
|
||||
|
||||
// GetEncoder 获取空中台输出的encoder
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
@ -415,16 +422,3 @@ func GetEncoder(option ...SetLoggerOptionFunc) zapcore.Encoder {
|
||||
}
|
||||
return zapcore.NewJSONEncoder(ec)
|
||||
}
|
||||
|
||||
// EnableWsLogger 启用wsLogger
|
||||
func EnableWsLogger(serverPort int, wsGroup string, router *gin.Engine) SetLoggerOptionFunc {
|
||||
return func(o *OptionLogger) {
|
||||
o.GinRouter = router
|
||||
o.WsServerProt = serverPort
|
||||
if len(wsGroup) == 0 {
|
||||
wsGroup = "ws-log"
|
||||
}
|
||||
o.WsGroup = wsGroup
|
||||
o.EnableWsLog = true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user