增加ws支持
This commit is contained in:
40
config.go
40
config.go
@ -9,12 +9,14 @@ package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"git.zhangdeman.cn/zhangdeman/websocket/storage"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
@ -217,23 +219,35 @@ 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 // 编码函数
|
||||
WsLoggerConnect storage.IConnection `json:"-"` // ws 日志连接管理实例
|
||||
}
|
||||
|
||||
// SetLoggerOptionFunc 设置日志配置
|
||||
type SetLoggerOptionFunc func(o *OptionLogger)
|
||||
|
||||
// WithWsLogger 设置ws管理实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:11 2024/7/22
|
||||
func WithWsLogger(connect storage.IConnection) SetLoggerOptionFunc {
|
||||
return func(o *OptionLogger) {
|
||||
o.WsLoggerConnect = connect
|
||||
}
|
||||
}
|
||||
|
||||
// WithCaller 打开文件行号记录
|
||||
func WithCaller() SetLoggerOptionFunc {
|
||||
return func(o *OptionLogger) {
|
||||
|
Reference in New Issue
Block a user