Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ var (
LibravatarService *libravatar.Libravatar

// Log settings
LogLevel string
LogRootPath string
LogModes []string
LogConfigs []string
Expand Down Expand Up @@ -659,6 +660,7 @@ func NewContext() {
}
homeDir = strings.Replace(homeDir, "\\", "/", -1)

LogLevel = getLogLevel("log", "LEVEL", "Info")
LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(AppWorkPath, "log"))
forcePathSeparator(LogRootPath)

Expand Down Expand Up @@ -1192,6 +1194,11 @@ var logLevels = map[string]string{
"Critical": "5",
}

func getLogLevel(section string, key string, defaultValue string) string {
validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
return Cfg.Section(section).Key(key).In(defaultValue, validLevels)
}

func newLogService() {
log.Info("Gitea v%s%s", AppVer, AppBuiltWith)

Expand All @@ -1216,11 +1223,8 @@ func newLogService() {
sec, _ = Cfg.NewSection("log." + mode)
}

validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
// Log level.
levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
validLevels)
levelName := getLogLevel("log."+mode, "LEVEL", LogLevel)
level, ok := logLevels[levelName]
if !ok {
log.Fatal(4, "Unknown log level: %s", levelName)
Expand Down Expand Up @@ -1284,11 +1288,8 @@ func NewXORMLogService(disableConsole bool) {
sec, _ = Cfg.NewSection("log." + mode)
}

validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
// Log level.
levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
validLevels)
levelName := getLogLevel("log."+mode, "LEVEL", LogLevel)
level, ok := logLevels[levelName]
if !ok {
log.Fatal(4, "Unknown log level: %s", levelName)
Expand Down
2 changes: 1 addition & 1 deletion routers/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
cfg.Section("session").Key("PROVIDER").SetValue("file")

cfg.Section("log").Key("MODE").SetValue("file")
cfg.Section("log").Key("LEVEL").SetValue("Info")
cfg.Section("log").Key("LEVEL").SetValue(setting.LogLevel)
cfg.Section("log").Key("ROOT_PATH").SetValue(form.LogRootPath)

cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
Expand Down