Commit 7178dcad by Torkel Odegaard

Windows: Fixed runtime issue with file logging config that casued errors on startup

parent a4462868
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"net/url" "net/url"
"os" "os"
"path" "path"
"encoding/json"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
...@@ -18,6 +19,7 @@ import ( ...@@ -18,6 +19,7 @@ import (
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/util"
) )
type Scheme string type Scheme string
...@@ -404,13 +406,13 @@ func readSessionConfig() { ...@@ -404,13 +406,13 @@ func readSessionConfig() {
} }
} }
var logLevels = map[string]string{ var logLevels = map[string]int{
"Trace": "0", "Trace": 0,
"Debug": "1", "Debug": 1,
"Info": "2", "Info": 2,
"Warn": "3", "Warn": 3,
"Error": "4", "Error": 4,
"Critical": "5", "Critical": 5,
} }
func initLogging(args *CommandLineArgs) { func initLogging(args *CommandLineArgs) {
...@@ -434,40 +436,52 @@ func initLogging(args *CommandLineArgs) { ...@@ -434,40 +436,52 @@ func initLogging(args *CommandLineArgs) {
log.Fatal(4, "Unknown log level: %s", levelName) log.Fatal(4, "Unknown log level: %s", levelName)
} }
var logCfg util.DynMap
// Generate log configuration. // Generate log configuration.
switch mode { switch mode {
case "console": case "console":
LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level) logCfg = util.DynMap{"level": level}
case "file": case "file":
logPath := sec.Key("file_name").MustString(path.Join(LogsPath, "grafana.log")) logPath := sec.Key("file_name").MustString(filepath.Join(LogsPath, "grafana.log"))
os.MkdirAll(path.Dir(logPath), os.ModePerm) os.MkdirAll(filepath.Dir(logPath), os.ModePerm)
LogConfigs[i] = fmt.Sprintf( logCfg = util.DynMap{
`{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level, "level": level,
logPath, "filename": logPath,
sec.Key("log_rotate").MustBool(true), "rotate": sec.Key("log_rotate").MustBool(true),
sec.Key("max_lines").MustInt(1000000), "maxlines": sec.Key("max_lines").MustInt(1000000),
1<<uint(sec.Key("max_size_shift").MustInt(28)), "maxsize": 1<<uint(sec.Key("max_size_shift").MustInt(28)),
sec.Key("daily_rotate").MustBool(true), "daily": sec.Key("daily_rotate").MustBool(true),
sec.Key("max_days").MustInt(7)) "maxdays": sec.Key("max_days").MustInt(7),
}
case "conn": case "conn":
LogConfigs[i] = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level, logCfg = util.DynMap{
sec.Key("reconnect_on_msg").MustBool(), "level": level,
sec.Key("reconnect").MustBool(), "reconnectOnMsg": sec.Key("reconnect_on_msg").MustBool(),
sec.Key("protocol").In("tcp", []string{"tcp", "unix", "udp"}), "reconnect": sec.Key("reconnect").MustBool(),
sec.Key("addr").MustString(":7020")) "net": sec.Key("protocol").In("tcp", []string{"tcp", "unix", "udp"}),
"addr": sec.Key("addr").MustString(":7020"),
}
case "smtp": case "smtp":
LogConfigs[i] = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level, logCfg = util.DynMap{
sec.Key("user").MustString("example@example.com"), "level": level,
sec.Key("passwd").MustString("******"), "user": sec.Key("user").MustString("example@example.com"),
sec.Key("host").MustString("127.0.0.1:25"), "passwd": sec.Key("passwd").MustString("******"),
sec.Key("receivers").MustString("[]"), "host": sec.Key("host").MustString("127.0.0.1:25"),
sec.Key("subject").MustString("Diagnostic message from serve")) "receivers": sec.Key("receivers").MustString("[]"),
"subject": sec.Key("subject").MustString("Diagnostic message from serve"),
}
case "database": case "database":
LogConfigs[i] = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level, logCfg = util.DynMap{
sec.Key("driver").String(), "level": level,
sec.Key("conn").String()) "driver": sec.Key("driver").String(),
"conn": sec.Key("conn").String(),
}
} }
cfgJsonBytes, _ := json.Marshal(logCfg)
LogConfigs[i] = string(cfgJsonBytes)
fmt.Printf("Config: %s\n", LogConfigs[i])
log.NewLogger(Cfg.Section("log").Key("buffer_len").MustInt64(10000), mode, LogConfigs[i]) log.NewLogger(Cfg.Section("log").Key("buffer_len").MustInt64(10000), mode, LogConfigs[i])
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment