Skip to content

Commit 3121a7a

Browse files
authored
Remove the default console logger when it is not set in the configuration (#602) (#960)
* Remove the default console logger when it is not set in the configuration * Added comment to new function (lint failure) * update based on PR comments (code style) * code style fix (thanks bkcsoft) * check if logger exists based on the l.outputs (like in l.DelLogger) instead of adapter, otherwise panic when reinstalling gitea (since the output adapter still exist, without outputs)
1 parent 61cdc32 commit 3121a7a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

modules/log/log.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ func NewLogger(bufLen int64, mode, config string) {
3939
}
4040
}
4141

42+
// DelLogger removes loggers that are for the given mode
43+
func DelLogger(mode string) error {
44+
for _, l := range loggers {
45+
if _, ok := l.outputs[mode]; ok {
46+
return l.DelLogger(mode)
47+
}
48+
}
49+
Trace("Log adapter %s not found, no need to delete", mode)
50+
return nil
51+
}
52+
4253
// NewGitLogger create a logger for git
4354
// FIXME: use same log level as other loggers.
4455
func NewGitLogger(logPath string) {

modules/setting/setting.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,16 @@ func newLogService() {
765765
LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
766766
LogConfigs = make([]string, len(LogModes))
767767

768+
useConsole := false
769+
for _, mode := range LogModes {
770+
if mode == "console" {
771+
useConsole = true
772+
}
773+
}
774+
if (!useConsole) {
775+
log.DelLogger("console")
776+
}
777+
768778
for i, mode := range LogModes {
769779
mode = strings.TrimSpace(mode)
770780

0 commit comments

Comments
 (0)