1 Star 0 Fork 27

caofangzi/wmq-go

forked from 狂奔的蜗牛./wmq-go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
logger.go 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
arraykeys@gmail.com 提交于 2017-06-07 11:35 . add access log
package main
import (
"github.com/snail007/mini-logger"
"github.com/snail007/mini-logger/writers/console"
"github.com/snail007/mini-logger/writers/files"
)
var log logger.MiniLogger
var accessLog logger.MiniLogger
//initLog
func initLog() {
var level uint8
switch cfg.GetString("log.console-level") {
case "debug":
level = logger.AllLevels
case "info":
level = logger.InfoLevel | logger.WarnLevel | logger.ErrorLevel | logger.FatalLevel
case "warn":
level = logger.WarnLevel | logger.ErrorLevel | logger.FatalLevel
case "error":
level = logger.ErrorLevel | logger.FatalLevel
case "fatal":
level = logger.FatalLevel
default:
level = 0
}
log = logger.New(false, nil)
log.AddWriter(console.NewDefault(), level)
cfgF := files.GetDefaultFileConfig()
cfgF.LogPath = cfg.GetString("log.dir")
cfgF.MaxBytes = cfg.GetInt64("log.FileMaxSize")
cfgF.MaxCount = cfg.GetInt("log.MaxCount")
cfgLevels := cfg.GetStringSlice("log.level")
if ok, _ := inArray("debug", cfgLevels); ok {
cfgF.FileNameSet["debug"] = logger.AllLevels
}
if ok, _ := inArray("info", cfgLevels); ok {
cfgF.FileNameSet["info"] = logger.InfoLevel
}
if ok, _ := inArray("error", cfgLevels); ok {
cfgF.FileNameSet["error"] = logger.WarnLevel | logger.ErrorLevel | logger.FatalLevel
}
log.AddWriter(files.New(cfgF), logger.AllLevels)
accessLog = logger.New(false, nil)
//accessLog.AddWriter(console.NewDefault(), logger.AllLevels)
if cfg.GetBool("log.access") {
accessCfg := files.GetDefaultFileConfig()
accessCfg.LogPath = cfg.GetString("log.dir")
accessCfg.MaxBytes = cfg.GetInt64("log.FileMaxSize")
accessCfg.MaxCount = cfg.GetInt("log.MaxCount")
accessCfg.FileNameSet = map[string]uint8{"access": logger.InfoLevel}
accessLog.AddWriter(files.New(accessCfg), logger.InfoLevel)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/caofangzi/wmq-go.git
git@gitee.com:caofangzi/wmq-go.git
caofangzi
wmq-go
wmq-go
master

搜索帮助