|
|
|
@ -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() { |
|
|
|
|
log.Info("%s %s", AppName, AppVer) |
|
|
|
|
|
|
|
|
|
// 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) |
|
|
|
|
} |
|
|
|
|
LogModes = strings.Split(Cfg.MustValue("log", "MODE", "console"), ",") |
|
|
|
|
LogConfigs = make([]string, len(LogModes)) |
|
|
|
|
for i, mode := range LogModes { |
|
|
|
|
mode = strings.TrimSpace(mode) |
|
|
|
|
modeSec := "log." + mode |
|
|
|
|
if _, err := Cfg.GetSection(modeSec); err != nil { |
|
|
|
|
qlog.Fatalf("Unknown log mode: %s\n", mode) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Log level.
|
|
|
|
|
levelName := Cfg.MustValue("log."+LogMode, "LEVEL", "Trace") |
|
|
|
|
level, ok := logLevels[levelName] |
|
|
|
|
if !ok { |
|
|
|
|
qlog.Fatalf("Unknown log level: %s\n", levelName) |
|
|
|
|
} |
|
|
|
|
// Log level.
|
|
|
|
|
levelName := Cfg.MustValue("log."+mode, "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<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)), |
|
|
|
|
Cfg.MustBool(modeSec, "DAILY_ROTATE", true), |
|
|
|
|
Cfg.MustInt(modeSec, "MAX_DAYS", 7)) |
|
|
|
|
case "conn": |
|
|
|
|
LogConfig = fmt.Sprintf(`{"level":"%s","reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level, |
|
|
|
|
Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false), |
|
|
|
|
Cfg.MustBool(modeSec, "RECONNECT", false), |
|
|
|
|
Cfg.MustValue(modeSec, "PROTOCOL", "tcp"), |
|
|
|
|
Cfg.MustValue(modeSec, "ADDR", ":7020")) |
|
|
|
|
case "smtp": |
|
|
|
|
LogConfig = fmt.Sprintf(`{"level":"%s","username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level, |
|
|
|
|
Cfg.MustValue(modeSec, "USER", "example@example.com"), |
|
|
|
|
Cfg.MustValue(modeSec, "PASSWD", "******"), |
|
|
|
|
Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"), |
|
|
|
|
Cfg.MustValue(modeSec, "RECEIVERS", "[]"), |
|
|
|
|
Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve")) |
|
|
|
|
case "database": |
|
|
|
|
LogConfig = fmt.Sprintf(`{"level":"%s","driver":"%s","conn":"%s"}`, level, |
|
|
|
|
Cfg.MustValue(modeSec, "Driver"), |
|
|
|
|
Cfg.MustValue(modeSec, "CONN")) |
|
|
|
|
} |
|
|
|
|
// Generate log configuration.
|
|
|
|
|
switch mode { |
|
|
|
|
case "console": |
|
|
|
|
LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level) |
|
|
|
|
case "file": |
|
|
|
|
logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log") |
|
|
|
|
os.MkdirAll(path.Dir(logPath), os.ModePerm) |
|
|
|
|
LogConfigs[i] = 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<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)), |
|
|
|
|
Cfg.MustBool(modeSec, "DAILY_ROTATE", true), |
|
|
|
|
Cfg.MustInt(modeSec, "MAX_DAYS", 7)) |
|
|
|
|
case "conn": |
|
|
|
|
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level, |
|
|
|
|
Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false), |
|
|
|
|
Cfg.MustBool(modeSec, "RECONNECT", false), |
|
|
|
|
Cfg.MustValue(modeSec, "PROTOCOL", "tcp"), |
|
|
|
|
Cfg.MustValue(modeSec, "ADDR", ":7020")) |
|
|
|
|
case "smtp": |
|
|
|
|
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level, |
|
|
|
|
Cfg.MustValue(modeSec, "USER", "example@example.com"), |
|
|
|
|
Cfg.MustValue(modeSec, "PASSWD", "******"), |
|
|
|
|
Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"), |
|
|
|
|
Cfg.MustValue(modeSec, "RECEIVERS", "[]"), |
|
|
|
|
Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve")) |
|
|
|
|
case "database": |
|
|
|
|
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","driver":"%s","conn":"%s"}`, level, |
|
|
|
|
Cfg.MustValue(modeSec, "Driver"), |
|
|
|
|
Cfg.MustValue(modeSec, "CONN")) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.Info("%s %s", AppName, AppVer) |
|
|
|
|
log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), LogMode, LogConfig) |
|
|
|
|
log.Info("Log Mode: %s(%s)", strings.Title(LogMode), levelName) |
|
|
|
|
log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), mode, LogConfigs[i]) |
|
|
|
|
log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newLdapService() { |
|
|
|
|