feat: 优化升级日志组织
This commit is contained in:
21
logger.go
21
logger.go
@@ -10,6 +10,7 @@ package logger
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
|
||||
@@ -23,11 +24,7 @@ import (
|
||||
)
|
||||
|
||||
// NewLogger 获取日志实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:05 下午 2021/1/2
|
||||
func NewLogger(inputLoggerLevel consts.LogLevel, splitConfig *RotateLogConfig, optionFunc ...SetLoggerOptionFunc) (*zap.Logger, error) {
|
||||
func NewLogger(inputLoggerLevel LogLevel, splitConfig *RotateLogConfig, optionFunc ...SetLoggerOptionFunc) (*zap.Logger, error) {
|
||||
if nil == splitConfig {
|
||||
return nil, errors.New("未配置日志切割规则")
|
||||
}
|
||||
@@ -87,10 +84,6 @@ func NewLogger(inputLoggerLevel consts.LogLevel, splitConfig *RotateLogConfig, o
|
||||
}
|
||||
|
||||
// NewConsoleLogger 获取控制台输出的日志实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 8:22 下午 2021/4/17
|
||||
func NewConsoleLogger(loggerLevel zapcore.Level, optionFunc ...SetLoggerOptionFunc) (*zap.Logger, error) {
|
||||
o := &OptionLogger{}
|
||||
|
||||
@@ -124,15 +117,11 @@ type Logger struct {
|
||||
}
|
||||
|
||||
// getWriter 获取日志实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:08 下午 2021/1/2
|
||||
func (l *Logger) getWriter() (io.Writer, error) {
|
||||
option := make([]rotatelogs.Option, 0)
|
||||
option = append(option, rotatelogs.WithRotationTime(l.splitConfig.TimeInterval))
|
||||
if l.splitConfig.MaxAge > 0 {
|
||||
option = append(option, rotatelogs.WithMaxAge(l.splitConfig.MaxAge))
|
||||
option = append(option, rotatelogs.WithMaxAge(time.Duration(l.splitConfig.MaxAge)*time.Second))
|
||||
}
|
||||
var (
|
||||
hook *rotatelogs.RotateLogs
|
||||
@@ -149,10 +138,6 @@ type wsWriter struct {
|
||||
}
|
||||
|
||||
// Write ws的writer
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:24 2024/7/22
|
||||
func (w *wsWriter) Write(p []byte) (n int, err error) {
|
||||
if nil == wsLoggerConnect {
|
||||
return 0, nil
|
||||
|
||||
Reference in New Issue
Block a user