summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwillemvd <willemvd@users.noreply.github.com>2017-01-17 07:02:35 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-01-17 14:02:35 +0800
commit8c2c7b802fa0d0da660834bcf2ae60887c0bfd4f (patch)
tree84e55229118f6da32cf322f90eb306a6a01f183f
parentd1006150fb3a82a8dd6e418578dc44474191bfd0 (diff)
downloadgitea-8c2c7b802fa0d0da660834bcf2ae60887c0bfd4f.tar.gz
gitea-8c2c7b802fa0d0da660834bcf2ae60887c0bfd4f.zip
Remove the default console logger when it is not set in the configuration (#602)
* 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)
-rw-r--r--modules/log/log.go11
-rw-r--r--modules/setting/setting.go10
2 files changed, 21 insertions, 0 deletions
diff --git a/modules/log/log.go b/modules/log/log.go
index 6ca6d3f7c1..8faf9416de 100644
--- a/modules/log/log.go
+++ b/modules/log/log.go
@@ -39,6 +39,17 @@ func NewLogger(bufLen int64, mode, config string) {
}
}
+// DelLogger removes loggers that are for the given mode
+func DelLogger(mode string) error {
+ for _, l := range loggers {
+ if _, ok := l.outputs[mode]; ok {
+ return l.DelLogger(mode)
+ }
+ }
+ Trace("Log adapter %s not found, no need to delete", mode)
+ return nil
+}
+
// NewGitLogger create a logger for git
// FIXME: use same log level as other loggers.
func NewGitLogger(logPath string) {
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index ab916c1b53..16177e889b 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -895,6 +895,16 @@ func newLogService() {
LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
LogConfigs = make([]string, len(LogModes))
+ useConsole := false
+ for _, mode := range LogModes {
+ if mode == "console" {
+ useConsole = true
+ }
+ }
+ if (!useConsole) {
+ log.DelLogger("console")
+ }
+
for i, mode := range LogModes {
mode = strings.TrimSpace(mode)