From 70173d2dc6067d332b7fa06ea0d0b215d437e71f Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 30 Dec 2022 21:58:15 +0800 Subject: [PATCH 1/2] feat: notice no more logs to console --- modules/setting/log.go | 29 ++++++++++++----------------- routers/init.go | 1 + 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/modules/setting/log.go b/modules/setting/log.go index 7372fc998d99d..2d8c075b1b62b 100644 --- a/modules/setting/log.go +++ b/modules/setting/log.go @@ -284,8 +284,6 @@ func newRouterLogService() { } func newLogService() { - log.Info("Gitea v%s%s", AppVer, AppBuiltWith) - options := newDefaultLogOptions() options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000) EnableSSHLog = Cfg.Section("log").Key("ENABLE_SSH_LOG").MustBool(false) @@ -297,24 +295,14 @@ func newLogService() { sections := strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",") useConsole := false - for i := 0; i < len(sections); i++ { - sections[i] = strings.TrimSpace(sections[i]) - if sections[i] == "console" { - useConsole = true - } - } - - if !useConsole { - err := log.DelLogger("console") - if err != nil { - log.Fatal("DelLogger: %v", err) - } - } - for _, name := range sections { - if len(name) == 0 { + name = strings.TrimSpace(name) + if name == "" { continue } + if name == "console" { + useConsole = true + } sec, err := Cfg.GetSection("log." + name + ".default") if err != nil { @@ -336,6 +324,13 @@ func newLogService() { AddLogDescription(log.DEFAULT, &description) + if !useConsole { + log.Info("According to the configuration, subsequent logs will not be printed to the console") + if err := log.DelLogger("console"); err != nil { + log.Fatal("DelLogger: %v", err) + } + } + // Finally redirect the default golog to here golog.SetFlags(0) golog.SetPrefix("") diff --git a/routers/init.go b/routers/init.go index 670191debc664..61af512220506 100644 --- a/routers/init.go +++ b/routers/init.go @@ -119,6 +119,7 @@ func GlobalInitInstalled(ctx context.Context) { log.Info("Log path: %s", setting.LogRootPath) log.Info("Configuration file: %s", setting.CustomConf) log.Info("Run Mode: %s", util.ToTitleCase(setting.RunMode)) + log.Info("Gitea v%s%s", setting.AppVer, setting.AppBuiltWith) // Setup i18n translation.InitLocales(ctx) From df0e36d6f7a5dd0b2d56ab13936d406e04ce3241 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 31 Dec 2022 15:05:12 +0800 Subject: [PATCH 2/2] Update modules/setting/log.go Co-authored-by: delvh --- modules/setting/log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setting/log.go b/modules/setting/log.go index 2d8c075b1b62b..8a2d47eda7670 100644 --- a/modules/setting/log.go +++ b/modules/setting/log.go @@ -327,7 +327,7 @@ func newLogService() { if !useConsole { log.Info("According to the configuration, subsequent logs will not be printed to the console") if err := log.DelLogger("console"); err != nil { - log.Fatal("DelLogger: %v", err) + log.Fatal("Cannot delete console logger: %v", err) } }