1 Star 0 Fork 0

庞飞 / multiapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
daily.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
庞飞 提交于 2023-10-03 17:10 . 合并主框架
package logger
import (
"errors"
"path"
"strings"
"time"
"gitee.com/pangxianfei/multiapp/config"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"github.com/rifflock/lfshook"
"github.com/sirupsen/logrus"
"gitee.com/pangxianfei/multiapp/log/formatter"
)
type Daily struct {
}
func (daily *Daily) Handle(channel string) (logrus.Hook, error) {
var hook logrus.Hook
logPath := config.GetString(channel + ".path")
if logPath == "" {
return hook, errors.New("error log path")
}
ext := path.Ext(logPath)
logPath = strings.ReplaceAll(logPath, ext, "")
writer, err := rotatelogs.New(
logPath+"-%Y-%m-%d"+ext,
rotatelogs.WithRotationTime(time.Duration(24)*time.Hour),
rotatelogs.WithRotationCount(uint(config.GetInt(channel+".days"))),
)
if err != nil {
return hook, errors.New("Config local file system for logger error: " + err.Error())
}
levels := getLevels(config.GetString(channel + ".level"))
writerMap := lfshook.WriterMap{}
for _, level := range levels {
writerMap[level] = writer
}
return lfshook.NewHook(
writerMap,
&formatter.General{},
), nil
}
Go
1
https://gitee.com/pangxianfei/multiapp.git
git@gitee.com:pangxianfei/multiapp.git
pangxianfei
multiapp
multiapp
v1.2.3

搜索帮助