diff --git a/common/config.go b/common/config.go index 29a6998ee072b9e976e10d9300c94f5796eb1963..0dddded88d61a40497701dddace45673039b2a53 100644 --- a/common/config.go +++ b/common/config.go @@ -25,6 +25,7 @@ import ( "io" "io/ioutil" "os" + "path/filepath" "regexp" "runtime" "strings" @@ -591,21 +592,14 @@ func readCmdFlags() error { Config.SamplingStatisticTarget = *samplingStatisticTarget Config.ConnTimeOut = *connTimeOut Config.QueryTimeOut = *queryTimeOut - Config.LogLevel = *logLevel - if strings.HasPrefix(*logOutput, "/") { + + if filepath.IsAbs(*logOutput) || *logOutput == "" { Config.LogOutput = *logOutput } else { - if BaseDir == "" { - Config.LogOutput = *logOutput - } else { - if runtime.GOOS == "windows" { - Config.LogOutput = *logOutput - } else { - Config.LogOutput = BaseDir + "/" + *logOutput - } - } + Config.LogOutput = filepath.Join(BaseDir, *logOutput) } + Config.ReportType = strings.ToLower(*reportType) Config.ReportCSS = *reportCSS Config.ReportJavascript = *reportJavascript @@ -615,12 +609,13 @@ func readCmdFlags() error { Config.IgnoreRules = strings.Split(*ignoreRules, ",") Config.RewriteRules = strings.Split(*rewriteRules, ",") *blackList = strings.TrimSpace(*blackList) - if strings.HasPrefix(*blackList, "/") || *blackList == "" { + + if filepath.IsAbs(*blackList) || *blackList == "" { Config.BlackList = *blackList } else { - pwd, _ := os.Getwd() - Config.BlackList = pwd + "/" + *blackList + Config.BlackList = filepath.Join(BaseDir, *blackList) } + Config.MaxJoinTableCount = *maxJoinTableCount Config.MaxGroupByColsCount = *maxGroupByColsCount Config.MaxDistinctCount = *maxDistinctCount @@ -697,8 +692,8 @@ func ParseConfig(configFile string) error { if configFile == "" { configs = []string{ "/etc/soar.yaml", - BaseDir + "/etc/soar.yaml", - BaseDir + "/soar.yaml", + filepath.Join(BaseDir, "etc", "soar.yaml"), + filepath.Join(BaseDir, "soar.yaml"), } } else { configs = []string{ diff --git a/common/logger.go b/common/logger.go index 6323fca2e4a15fdeeca532bc75ad90db6145cdec..68dda20178f9a5d678ac0df46281c213207cf244 100644 --- a/common/logger.go +++ b/common/logger.go @@ -17,6 +17,7 @@ package common import ( + "encoding/json" "fmt" "regexp" "runtime" @@ -40,7 +41,16 @@ func init() { func LoggerInit() { Log.SetLevel(Config.LogLevel) 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)) + logConfig := map[string]interface{}{ + "filename": Config.LogOutput, + "level": 7, + "maxlines": 0, + "maxsize": 0, + "daily": false, + "maxdays": 0, + } + logConfigJson, _ := json.Marshal(logConfig) + err := Log.SetLogger(logs.AdapterFile, fmt.Sprintf(string(logConfigJson))) if err != nil { fmt.Println(err.Error()) }