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 (
"net/url"
"os"
"path"
"encoding/json"
"path/filepath"
"regexp"
"runtime"
......@@ -18,6 +19,7 @@ import (
"gopkg.in/ini.v1"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/util"
)
type Scheme string
......@@ -404,13 +406,13 @@ func readSessionConfig() {
}
}
var logLevels = map[string]string{
"Trace": "0",
"Debug": "1",
"Info": "2",
"Warn": "3",
"Error": "4",
"Critical": "5",
var logLevels = map[string]int{
"Trace": 0,
"Debug": 1,
"Info": 2,
"Warn": 3,
"Error": 4,
"Critical": 5,
}
func initLogging(args *CommandLineArgs) {
......@@ -434,40 +436,52 @@ func initLogging(args *CommandLineArgs) {
log.Fatal(4, "Unknown log level: %s", levelName)
}
var logCfg util.DynMap
// Generate log configuration.
switch mode {
case "console":
LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level)
logCfg = util.DynMap{"level": level}
case "file":
logPath := sec.Key("file_name").MustString(path.Join(LogsPath, "grafana.log"))
os.MkdirAll(path.Dir(logPath), os.ModePerm)
LogConfigs[i] = fmt.Sprintf(
`{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
logPath,
sec.Key("log_rotate").MustBool(true),
sec.Key("max_lines").MustInt(1000000),
1<<uint(sec.Key("max_size_shift").MustInt(28)),
sec.Key("daily_rotate").MustBool(true),
sec.Key("max_days").MustInt(7))
logPath := sec.Key("file_name").MustString(filepath.Join(LogsPath, "grafana.log"))
os.MkdirAll(filepath.Dir(logPath), os.ModePerm)
logCfg = util.DynMap{
"level": level,
"filename": logPath,
"rotate": sec.Key("log_rotate").MustBool(true),
"maxlines": sec.Key("max_lines").MustInt(1000000),
"maxsize": 1<<uint(sec.Key("max_size_shift").MustInt(28)),
"daily": sec.Key("daily_rotate").MustBool(true),
"maxdays": sec.Key("max_days").MustInt(7),
}
case "conn":
LogConfigs[i] = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
sec.Key("reconnect_on_msg").MustBool(),
sec.Key("reconnect").MustBool(),
sec.Key("protocol").In("tcp", []string{"tcp", "unix", "udp"}),
sec.Key("addr").MustString(":7020"))
logCfg = util.DynMap{
"level": level,
"reconnectOnMsg": sec.Key("reconnect_on_msg").MustBool(),
"reconnect": sec.Key("reconnect").MustBool(),
"net": sec.Key("protocol").In("tcp", []string{"tcp", "unix", "udp"}),
"addr": sec.Key("addr").MustString(":7020"),
}
case "smtp":
LogConfigs[i] = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level,
sec.Key("user").MustString("example@example.com"),
sec.Key("passwd").MustString("******"),
sec.Key("host").MustString("127.0.0.1:25"),
sec.Key("receivers").MustString("[]"),
sec.Key("subject").MustString("Diagnostic message from serve"))
logCfg = util.DynMap{
"level": level,
"user": sec.Key("user").MustString("example@example.com"),
"passwd": sec.Key("passwd").MustString("******"),
"host": sec.Key("host").MustString("127.0.0.1:25"),
"receivers": sec.Key("receivers").MustString("[]"),
"subject": sec.Key("subject").MustString("Diagnostic message from serve"),
}
case "database":
LogConfigs[i] = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level,
sec.Key("driver").String(),
sec.Key("conn").String())
logCfg = util.DynMap{
"level": level,
"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])
}
}
......
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