mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-09 19:31:21 +01:00
Reminder for no more logs to console (#22282)
Even if the log mode is `file`, there are still few logs printed to the console at the very beginning. That's fine but confusing. Someone will think the console is the only place to find logs, and get nothing helpful. See https://github.com/go-gitea/gitea/issues/22274#issuecomment-1367917717. There should be a reminder that there are no more logs to the console. And to avoid log loss, we should add configured loggers first, then remove console logger if there's no `console` in the mode. Tests with `MODE = file`: Before: <img width="1792" alt="image" src="https://user-images.githubusercontent.com/9418365/210079862-d591677f-347e-46ed-a548-bb2ddbb0885c.png"> After: <img width="1792" alt="image" src="https://user-images.githubusercontent.com/9418365/210080002-d66cc418-6888-4909-b370-d03f5986ef41.png"> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
parent
9c8fc7f677
commit
f8e93ce423
2 changed files with 13 additions and 17 deletions
|
@ -284,8 +284,6 @@ func newRouterLogService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLogService() {
|
func newLogService() {
|
||||||
log.Info("Gitea v%s%s", AppVer, AppBuiltWith)
|
|
||||||
|
|
||||||
options := newDefaultLogOptions()
|
options := newDefaultLogOptions()
|
||||||
options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
|
options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
|
||||||
EnableSSHLog = Cfg.Section("log").Key("ENABLE_SSH_LOG").MustBool(false)
|
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"), ",")
|
sections := strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
|
||||||
|
|
||||||
useConsole := false
|
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 {
|
for _, name := range sections {
|
||||||
if len(name) == 0 {
|
name = strings.TrimSpace(name)
|
||||||
|
if name == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if name == "console" {
|
||||||
|
useConsole = true
|
||||||
|
}
|
||||||
|
|
||||||
sec, err := Cfg.GetSection("log." + name + ".default")
|
sec, err := Cfg.GetSection("log." + name + ".default")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -336,6 +324,13 @@ func newLogService() {
|
||||||
|
|
||||||
AddLogDescription(log.DEFAULT, &description)
|
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("Cannot delete console logger: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Finally redirect the default golog to here
|
// Finally redirect the default golog to here
|
||||||
golog.SetFlags(0)
|
golog.SetFlags(0)
|
||||||
golog.SetPrefix("")
|
golog.SetPrefix("")
|
||||||
|
|
|
@ -119,6 +119,7 @@ func GlobalInitInstalled(ctx context.Context) {
|
||||||
log.Info("Log path: %s", setting.LogRootPath)
|
log.Info("Log path: %s", setting.LogRootPath)
|
||||||
log.Info("Configuration file: %s", setting.CustomConf)
|
log.Info("Configuration file: %s", setting.CustomConf)
|
||||||
log.Info("Run Mode: %s", util.ToTitleCase(setting.RunMode))
|
log.Info("Run Mode: %s", util.ToTitleCase(setting.RunMode))
|
||||||
|
log.Info("Gitea v%s%s", setting.AppVer, setting.AppBuiltWith)
|
||||||
|
|
||||||
// Setup i18n
|
// Setup i18n
|
||||||
translation.InitLocales(ctx)
|
translation.InitLocales(ctx)
|
||||||
|
|
Loading…
Reference in a new issue