Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use level config in log section when sub log section not set level #15176

Merged
merged 3 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions modules/setting/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ var (
}

// Log settings
LogLevel string
LogLevel log.Level
StacktraceLogLevel string
LogRootPath string
DisableRouterLog bool
Expand Down Expand Up @@ -553,7 +553,7 @@ func NewContext() {
}
homeDir = strings.ReplaceAll(homeDir, "\\", "/")

LogLevel = getLogLevel(Cfg.Section("log"), "LEVEL", "Info")
LogLevel = getLogLevel(Cfg.Section("log"), "LEVEL", log.INFO)
StacktraceLogLevel = getStacktraceLogLevel(Cfg.Section("log"), "STACKTRACE_LEVEL", "None")
LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(AppWorkPath, "log"))
forcePathSeparator(LogRootPath)
Expand Down
2 changes: 1 addition & 1 deletion routers/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func InstallPost(ctx *context.Context) {
cfg.Section("session").Key("PROVIDER").SetValue("file")

cfg.Section("log").Key("MODE").SetValue("console")
cfg.Section("log").Key("LEVEL").SetValue(setting.LogLevel)
cfg.Section("log").Key("LEVEL").SetValue(setting.LogLevel.String())
cfg.Section("log").Key("ROOT_PATH").SetValue(form.LogRootPath)
cfg.Section("log").Key("ROUTER").SetValue("console")

Expand Down