Skip to content

Commit 57edc31

Browse files
Piotr Orzechowskilunny
authored andcommitted
Default log level to Info without hardcoding it in installer (#3041)
1 parent 9a8805d commit 57edc31

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

modules/setting/setting.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ var (
331331
LibravatarService *libravatar.Libravatar
332332

333333
// Log settings
334+
LogLevel string
334335
LogRootPath string
335336
LogModes []string
336337
LogConfigs []string
@@ -659,6 +660,7 @@ func NewContext() {
659660
}
660661
homeDir = strings.Replace(homeDir, "\\", "/", -1)
661662

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

@@ -1192,6 +1194,11 @@ var logLevels = map[string]string{
11921194
"Critical": "5",
11931195
}
11941196

1197+
func getLogLevel(section string, key string, defaultValue string) string {
1198+
validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
1199+
return Cfg.Section(section).Key(key).In(defaultValue, validLevels)
1200+
}
1201+
11951202
func newLogService() {
11961203
log.Info("Gitea v%s%s", AppVer, AppBuiltWith)
11971204

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

1219-
validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
12201226
// Log level.
1221-
levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
1222-
Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
1223-
validLevels)
1227+
levelName := getLogLevel("log."+mode, "LEVEL", LogLevel)
12241228
level, ok := logLevels[levelName]
12251229
if !ok {
12261230
log.Fatal(4, "Unknown log level: %s", levelName)
@@ -1284,11 +1288,8 @@ func NewXORMLogService(disableConsole bool) {
12841288
sec, _ = Cfg.NewSection("log." + mode)
12851289
}
12861290

1287-
validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
12881291
// Log level.
1289-
levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
1290-
Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
1291-
validLevels)
1292+
levelName := getLogLevel("log."+mode, "LEVEL", LogLevel)
12921293
level, ok := logLevels[levelName]
12931294
if !ok {
12941295
log.Fatal(4, "Unknown log level: %s", levelName)

routers/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
310310
cfg.Section("session").Key("PROVIDER").SetValue("file")
311311

312312
cfg.Section("log").Key("MODE").SetValue("file")
313-
cfg.Section("log").Key("LEVEL").SetValue("Info")
313+
cfg.Section("log").Key("LEVEL").SetValue(setting.LogLevel)
314314
cfg.Section("log").Key("ROOT_PATH").SetValue(form.LogRootPath)
315315

316316
cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")

0 commit comments

Comments
 (0)