diff --git a/common/config.go b/common/config.go index c4f795418a9b6eb26cd75300301e004698a73664..c0b4c7921a794166f7f6ea0338ff9cf070880f30 100644 --- a/common/config.go +++ b/common/config.go @@ -131,14 +131,6 @@ type Configuration struct { MaxPrettySQLLength int `yaml:"max-pretty-sql-length"` // 超出该长度的SQL会转换成指纹输出 } -// getDefaultLogOutput get default log-output by runtime.GOOS -func getDefaultLogOutput() string { - if runtime.GOOS == "windows" { - return "nul" - } - return os.Stderr.Name() -} - // Config 默认设置 var Config = &Configuration{ OnlineDSN: &dsn{ @@ -178,7 +170,7 @@ var Config = &Configuration{ SpaghettiQueryLength: 2048, AllowDropIndex: false, LogLevel: 3, - LogOutput: getDefaultLogOutput(), + LogOutput: "soar.log", ReportType: "markdown", ReportCSS: "", ReportJavascript: "", diff --git a/common/config_test.go b/common/config_test.go index 7f9a5694812f021fc40e3a33811c22405b4cc581..48f5a7acdcda34fc26ad604e69d310c1c9244b34 100644 --- a/common/config_test.go +++ b/common/config_test.go @@ -19,7 +19,6 @@ package common import ( "flag" "os" - "runtime" "testing" "github.com/kr/pretty" @@ -27,17 +26,6 @@ import ( var update = flag.Bool("update", false, "update .golden files") -func TestGetDefaultLogOutput(t *testing.T) { - output := getDefaultLogOutput() - if runtime.GOOS == "windows" && output != "nul" { - t.Error("windows default -log-output not nul") - } - - if runtime.GOOS != "windows" && output != "/dev/stderr" { - t.Error("default -log-output not /dev/stderr") - } -} - func TestParseConfig(t *testing.T) { err := ParseConfig("") if err != nil { diff --git a/common/logger.go b/common/logger.go index 77059cb7b5b5154c26873006c2c8c2bf105ac7b1..6323fca2e4a15fdeeca532bc75ad90db6145cdec 100644 --- a/common/logger.go +++ b/common/logger.go @@ -39,17 +39,10 @@ func init() { // LoggerInit Log配置初始化 func LoggerInit() { Log.SetLevel(Config.LogLevel) - if Config.LogOutput == logs.AdapterConsole { - err := Log.SetLogger(logs.AdapterConsole) - if err != nil { - fmt.Println(err.Error()) - } - } else { - func() { _ = Log.DelLogger(logs.AdapterFile) }() - err := Log.SetLogger(logs.AdapterFile, fmt.Sprintf(`{"filename":"%s","level":7,"maxlines":0,"maxsize":0,"daily":false,"maxdays":0}`, Config.LogOutput)) - if err != nil { - fmt.Println(err.Error()) - } + func() { _ = Log.DelLogger(logs.AdapterFile) }() + err := Log.SetLogger(logs.AdapterFile, fmt.Sprintf(`{"filename":"%s","level":7,"maxlines":0,"maxsize":0,"daily":false,"maxdays":0}`, Config.LogOutput)) + if err != nil { + fmt.Println(err.Error()) } }