diff options
author | a1012112796 <1012112796@qq.com> | 2021-03-29 03:08:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-28 20:08:19 +0100 |
commit | 3273fb9af18b9356d3c472bf23e9fbb8c7d681f3 (patch) | |
tree | 1860c24521269946d558ec60d521fc91a04f9c39 /modules/setting/log.go | |
parent | 82d1a7fb17ea549b17ef30711e0fa7e136acb880 (diff) | |
download | gitea-3273fb9af18b9356d3c472bf23e9fbb8c7d681f3.tar.gz gitea-3273fb9af18b9356d3c472bf23e9fbb8c7d681f3.zip |
use level config in main section when subsection not set level (#15176)
in previouse if a log subsetcion not set level
it will use ``info`` as default value.
this pr will make default value (``[log] -> LEVEL``) useable.
example config:
```INI
[log]
MODE = console
LEVEL = Trace
[log.console]
LEVEL =
STDERR = false
```
previous result:
```JSON
// console:
{
"level": "info",
...................
}
```
after change:
```JSON
// console:
{
"level": "track",
...................
}
```
Signed-off-by: a1012112796 <1012112796@qq.com>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/setting/log.go')
-rw-r--r-- | modules/setting/log.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/modules/setting/log.go b/modules/setting/log.go index 9bbeee27a2..44017b1138 100644 --- a/modules/setting/log.go +++ b/modules/setting/log.go @@ -94,7 +94,7 @@ type defaultLogOptions struct { func newDefaultLogOptions() defaultLogOptions { return defaultLogOptions{ - levelName: LogLevel, + levelName: LogLevel.String(), flags: "stdflags", filename: filepath.Join(LogRootPath, "gitea.log"), bufferLength: 10000, @@ -115,9 +115,9 @@ type LogDescription struct { SubLogDescriptions []SubLogDescription } -func getLogLevel(section *ini.Section, key string, defaultValue string) string { - value := section.Key(key).MustString("info") - return log.FromString(value).String() +func getLogLevel(section *ini.Section, key string, defaultValue log.Level) log.Level { + value := section.Key(key).MustString(defaultValue.String()) + return log.FromString(value) } func getStacktraceLogLevel(section *ini.Section, key string, defaultValue string) string { @@ -126,8 +126,7 @@ func getStacktraceLogLevel(section *ini.Section, key string, defaultValue string } func generateLogConfig(sec *ini.Section, name string, defaults defaultLogOptions) (mode, jsonConfig, levelName string) { - levelName = getLogLevel(sec, "LEVEL", LogLevel) - level := log.FromString(levelName) + level := getLogLevel(sec, "LEVEL", LogLevel) stacktraceLevelName := getStacktraceLogLevel(sec, "STACKTRACE_LEVEL", StacktraceLogLevel) stacktraceLevel := log.FromString(stacktraceLevelName) mode = name |