未验证 提交 ebcb39eb 编写于 作者: X xiyangxixian 提交者: GitHub

Merge pull request #1 from XiaoMi/master

sync master
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
...@@ -591,21 +592,14 @@ func readCmdFlags() error { ...@@ -591,21 +592,14 @@ func readCmdFlags() error {
Config.SamplingStatisticTarget = *samplingStatisticTarget Config.SamplingStatisticTarget = *samplingStatisticTarget
Config.ConnTimeOut = *connTimeOut Config.ConnTimeOut = *connTimeOut
Config.QueryTimeOut = *queryTimeOut Config.QueryTimeOut = *queryTimeOut
Config.LogLevel = *logLevel Config.LogLevel = *logLevel
if strings.HasPrefix(*logOutput, "/") {
if filepath.IsAbs(*logOutput) || *logOutput == "" {
Config.LogOutput = *logOutput Config.LogOutput = *logOutput
} else { } else {
if BaseDir == "" { Config.LogOutput = filepath.Join(BaseDir, *logOutput)
Config.LogOutput = *logOutput
} else {
if runtime.GOOS == "windows" {
Config.LogOutput = *logOutput
} else {
Config.LogOutput = BaseDir + "/" + *logOutput
}
}
} }
Config.ReportType = strings.ToLower(*reportType) Config.ReportType = strings.ToLower(*reportType)
Config.ReportCSS = *reportCSS Config.ReportCSS = *reportCSS
Config.ReportJavascript = *reportJavascript Config.ReportJavascript = *reportJavascript
...@@ -615,12 +609,13 @@ func readCmdFlags() error { ...@@ -615,12 +609,13 @@ func readCmdFlags() error {
Config.IgnoreRules = strings.Split(*ignoreRules, ",") Config.IgnoreRules = strings.Split(*ignoreRules, ",")
Config.RewriteRules = strings.Split(*rewriteRules, ",") Config.RewriteRules = strings.Split(*rewriteRules, ",")
*blackList = strings.TrimSpace(*blackList) *blackList = strings.TrimSpace(*blackList)
if strings.HasPrefix(*blackList, "/") || *blackList == "" {
if filepath.IsAbs(*blackList) || *blackList == "" {
Config.BlackList = *blackList Config.BlackList = *blackList
} else { } else {
pwd, _ := os.Getwd() Config.BlackList = filepath.Join(BaseDir, *blackList)
Config.BlackList = pwd + "/" + *blackList
} }
Config.MaxJoinTableCount = *maxJoinTableCount Config.MaxJoinTableCount = *maxJoinTableCount
Config.MaxGroupByColsCount = *maxGroupByColsCount Config.MaxGroupByColsCount = *maxGroupByColsCount
Config.MaxDistinctCount = *maxDistinctCount Config.MaxDistinctCount = *maxDistinctCount
...@@ -697,8 +692,8 @@ func ParseConfig(configFile string) error { ...@@ -697,8 +692,8 @@ func ParseConfig(configFile string) error {
if configFile == "" { if configFile == "" {
configs = []string{ configs = []string{
"/etc/soar.yaml", "/etc/soar.yaml",
BaseDir + "/etc/soar.yaml", filepath.Join(BaseDir, "etc", "soar.yaml"),
BaseDir + "/soar.yaml", filepath.Join(BaseDir, "soar.yaml"),
} }
} else { } else {
configs = []string{ configs = []string{
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package common package common
import ( import (
"encoding/json"
"fmt" "fmt"
"regexp" "regexp"
"runtime" "runtime"
...@@ -40,7 +41,16 @@ func init() { ...@@ -40,7 +41,16 @@ func init() {
func LoggerInit() { func LoggerInit() {
Log.SetLevel(Config.LogLevel) Log.SetLevel(Config.LogLevel)
func() { _ = Log.DelLogger(logs.AdapterFile) }() 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 { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册