Skip to content

Commit f8e93ce

Browse files
wolfogrelunnydelvh
authored
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 #22274 (comment). 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 <[email protected]> Co-authored-by: delvh <[email protected]>
1 parent 9c8fc7f commit f8e93ce

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

modules/setting/log.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ func newRouterLogService() {
284284
}
285285

286286
func newLogService() {
287-
log.Info("Gitea v%s%s", AppVer, AppBuiltWith)
288-
289287
options := newDefaultLogOptions()
290288
options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
291289
EnableSSHLog = Cfg.Section("log").Key("ENABLE_SSH_LOG").MustBool(false)
@@ -297,24 +295,14 @@ func newLogService() {
297295
sections := strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
298296

299297
useConsole := false
300-
for i := 0; i < len(sections); i++ {
301-
sections[i] = strings.TrimSpace(sections[i])
302-
if sections[i] == "console" {
303-
useConsole = true
304-
}
305-
}
306-
307-
if !useConsole {
308-
err := log.DelLogger("console")
309-
if err != nil {
310-
log.Fatal("DelLogger: %v", err)
311-
}
312-
}
313-
314298
for _, name := range sections {
315-
if len(name) == 0 {
299+
name = strings.TrimSpace(name)
300+
if name == "" {
316301
continue
317302
}
303+
if name == "console" {
304+
useConsole = true
305+
}
318306

319307
sec, err := Cfg.GetSection("log." + name + ".default")
320308
if err != nil {
@@ -336,6 +324,13 @@ func newLogService() {
336324

337325
AddLogDescription(log.DEFAULT, &description)
338326

327+
if !useConsole {
328+
log.Info("According to the configuration, subsequent logs will not be printed to the console")
329+
if err := log.DelLogger("console"); err != nil {
330+
log.Fatal("Cannot delete console logger: %v", err)
331+
}
332+
}
333+
339334
// Finally redirect the default golog to here
340335
golog.SetFlags(0)
341336
golog.SetPrefix("")

routers/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func GlobalInitInstalled(ctx context.Context) {
119119
log.Info("Log path: %s", setting.LogRootPath)
120120
log.Info("Configuration file: %s", setting.CustomConf)
121121
log.Info("Run Mode: %s", util.ToTitleCase(setting.RunMode))
122+
log.Info("Gitea v%s%s", setting.AppVer, setting.AppBuiltWith)
122123

123124
// Setup i18n
124125
translation.InitLocales(ctx)

0 commit comments

Comments
 (0)