feat: 改用 logrus 输出日志
This commit is contained in:
@@ -65,15 +65,3 @@ func readConfig() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
initFlags()
|
||||
|
||||
//配置文件初始化
|
||||
if readConfig() != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
//初始化常变量
|
||||
Timeout = time.Duration(Config.Settings.Basic.Timeout) * time.Second
|
||||
}
|
||||
|
||||
21
global/init.go
Normal file
21
global/init.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
initFlags()
|
||||
|
||||
//配置文件初始化
|
||||
if readConfig() != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
//初始化常变量
|
||||
Timeout = time.Duration(Config.Settings.Basic.Timeout) * time.Second
|
||||
|
||||
//初始化日志配置
|
||||
initLog()
|
||||
}
|
||||
34
global/log.go
Normal file
34
global/log.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func initLog() {
|
||||
if Config.Settings.Debug.Enable {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
if Config.Settings.Debug.WriteLog {
|
||||
//日志路径初始化与处理
|
||||
if !strings.HasSuffix(Config.Settings.Debug.LogPath, "/") {
|
||||
Config.Settings.Debug.LogPath += "/"
|
||||
}
|
||||
e := os.MkdirAll(Config.Settings.Debug.LogPath, os.ModePerm)
|
||||
if e != nil {
|
||||
log.Fatalln(e)
|
||||
}
|
||||
|
||||
f, e := os.OpenFile(Config.Settings.Debug.LogPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 700)
|
||||
if e != nil {
|
||||
log.Fatalln(e)
|
||||
}
|
||||
|
||||
//设置双重输出
|
||||
mw := io.MultiWriter(os.Stdout, f)
|
||||
log.SetOutput(mw)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user