未验证 提交 1bdc431a 编写于 作者: martianzhang's avatar martianzhang 提交者: GitHub

Merge pull request #149 from xiyangxixian/master

fix SetLooger && update filepath
......@@ -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{
......
......@@ -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())
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册