feat: 更改 debug 模块为 log 模块 #11
This commit is contained in:
@@ -36,8 +36,8 @@ func readConfig() {
|
|||||||
Guardian: srunModels.Guardian{
|
Guardian: srunModels.Guardian{
|
||||||
Duration: 300,
|
Duration: 300,
|
||||||
},
|
},
|
||||||
Debug: srunModels.Debug{
|
Log: srunModels.Log{
|
||||||
LogPath: "./",
|
FilePath: "./",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -9,20 +9,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func initLog() {
|
func initLog() {
|
||||||
if Config.Settings.Debug.Enable {
|
if Config.Settings.Log.DebugLevel {
|
||||||
log.SetLevel(log.DebugLevel)
|
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 Config.Settings.Log.WriteFile {
|
||||||
|
//日志路径初始化与处理
|
||||||
|
if !strings.HasSuffix(Config.Settings.Log.FilePath, "/") {
|
||||||
|
Config.Settings.Log.FilePath += "/"
|
||||||
|
}
|
||||||
|
e := os.MkdirAll(Config.Settings.Log.FilePath, os.ModePerm)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Fatalln(e)
|
log.Fatalln(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
f, e := os.OpenFile(Config.Settings.Debug.LogPath+time.Now().Format("2006.01.02-15.04.05")+".log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 700)
|
if Config.Settings.Log.FileName == "" {
|
||||||
|
Config.Settings.Log.FileName = time.Now().Format("2006.01.02-15.04.05") + ".log"
|
||||||
|
}
|
||||||
|
|
||||||
|
f, e := os.OpenFile(Config.Settings.Log.FilePath+Config.Settings.Log.FileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 700)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Fatalln(e)
|
log.Fatalln(e)
|
||||||
}
|
}
|
||||||
@@ -32,4 +37,3 @@ func initLog() {
|
|||||||
log.SetOutput(mw)
|
log.SetOutput(mw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -19,17 +19,18 @@ type Basic struct {
|
|||||||
Interfaces string `json:"interfaces" yaml:"interfaces" mapstructure:"interfaces"`
|
Interfaces string `json:"interfaces" yaml:"interfaces" mapstructure:"interfaces"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Log struct {
|
||||||
|
DebugLevel bool `json:"debug_level" yaml:"debug_level" mapstructure:"debug_level"`
|
||||||
|
WriteFile bool `json:"write_file" yaml:"write_file" mapstructure:"write_file"`
|
||||||
|
FilePath string `json:"log_path" yaml:"log_path" mapstructure:"log_path"`
|
||||||
|
FileName string `json:"log_name" yaml:"log_name" mapstructure:"log_name"`
|
||||||
|
}
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
Basic Basic `json:"basic" yaml:"basic" mapstructure:"basic"`
|
Basic Basic `json:"basic" yaml:"basic" mapstructure:"basic"`
|
||||||
Guardian Guardian `json:"guardian" yaml:"guardian" mapstructure:"guardian"`
|
Guardian Guardian `json:"guardian" yaml:"guardian" mapstructure:"guardian"`
|
||||||
Daemon Daemon `json:"daemon" yaml:"daemon" mapstructure:"daemon"`
|
Daemon Daemon `json:"daemon" yaml:"daemon" mapstructure:"daemon"`
|
||||||
Debug Debug `json:"debug" yaml:"debug" mapstructure:"debug"`
|
Log Log
|
||||||
}
|
|
||||||
|
|
||||||
type Debug struct {
|
|
||||||
Enable bool `json:"enable" yaml:"enable" mapstructure:"enable"`
|
|
||||||
WriteLog bool `json:"write_log" yaml:"write_log" mapstructure:"write_log"`
|
|
||||||
LogPath string `json:"log_path" yaml:"log_path" mapstructure:"log_path"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user