From 0970d6cc38a79c57ffe8e3c85687f7c7c49059be Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 11 May 2014 14:37:12 -0400 Subject: [PATCH] Log to different adapter according to level --- conf/app.ini | 7 ++- modules/base/conf.go | 109 +++++++++++++++++++----------------- modules/log/log.go | 41 ++++++++++---- routers/admin/admin.go | 10 +++- templates/admin/config.tmpl | 6 +- 5 files changed, 104 insertions(+), 69 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index f20665eab..16a1e2cd0 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -143,9 +143,9 @@ HOST = PROVIDER = file ; Provider config options ; memory: not have any config yet -; file: session file path, e.g. data/sessions -; redis: config like redis server addr, poolSize, password, e.g. 127.0.0.1:6379,100,astaxie -; mysql: go-sql-driver/mysql dsn config string, e.g. root:password@/session_table +; file: session file path, e.g. "data/sessions" +; redis: config like redis server addr, poolSize, password, e.g. "127.0.0.1:6379,100,astaxie" +; mysql: go-sql-driver/mysql dsn config string, e.g. "root:password@/session_table" PROVIDER_CONFIG = data/sessions ; Session cookie name COOKIE_NAME = i_like_gogits @@ -169,6 +169,7 @@ DISABLE_GRAVATAR = false [log] ; Either "console", "file", "conn", "smtp" or "database", default is "console" +; Use comma to separate multiple modes, e.g. "console, file" MODE = console ; Buffer length of channel, keep it as it is if you don't know what it is. BUFFER_LEN = 10000 diff --git a/modules/base/conf.go b/modules/base/conf.go index 99bac9006..c38d33577 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -70,8 +70,8 @@ var ( MailService *Mailer OauthService *Oauther - LogMode string - LogConfig string + LogModes []string + LogConfigs []string Cache cache.Cache CacheAdapter string @@ -130,57 +130,62 @@ func newService() { } func newLogService() { - // Get and check log mode. - LogMode = Cfg.MustValue("log", "MODE", "console") - modeSec := "log." + LogMode - if _, err := Cfg.GetSection(modeSec); err != nil { - qlog.Fatalf("Unknown log mode: %s\n", LogMode) - } - - // Log level. - levelName := Cfg.MustValue("log."+LogMode, "LEVEL", "Trace") - level, ok := logLevels[levelName] - if !ok { - qlog.Fatalf("Unknown log level: %s\n", levelName) - } - - // Generate log configuration. - switch LogMode { - case "console": - LogConfig = fmt.Sprintf(`{"level":%s}`, level) - case "file": - logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log") - os.MkdirAll(path.Dir(logPath), os.ModePerm) - LogConfig = fmt.Sprintf( - `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level, - logPath, - Cfg.MustBool(modeSec, "LOG_ROTATE", true), - Cfg.MustInt(modeSec, "MAX_LINES", 1000000), - 1<
+ {{range .Loggers}}
Log Mode
-
{{.LogMode}}
+
{{.Mode}}
Log Config
-
{{.LogConfig}}
+
{{.Config}}
+ {{end}}