aboutsummaryrefslogtreecommitdiffstats
path: root/modules/setting
diff options
context:
space:
mode:
Diffstat (limited to 'modules/setting')
-rw-r--r--modules/setting/cache.go2
-rw-r--r--modules/setting/cron.go2
-rw-r--r--modules/setting/git.go4
-rw-r--r--modules/setting/log.go375
-rw-r--r--modules/setting/mailer.go4
-rw-r--r--modules/setting/repository.go12
-rw-r--r--modules/setting/setting.go110
7 files changed, 312 insertions, 197 deletions
diff --git a/modules/setting/cache.go b/modules/setting/cache.go
index cbe73cf4e3..babb62baea 100644
--- a/modules/setting/cache.go
+++ b/modules/setting/cache.go
@@ -35,7 +35,7 @@ func newCacheService() {
case "redis", "memcache":
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
default:
- log.Fatal(4, "Unknown cache adapter: %s", CacheService.Adapter)
+ log.Fatal("Unknown cache adapter: %s", CacheService.Adapter)
}
CacheService.TTL = sec.Key("ITEM_TTL").MustDuration(16 * time.Hour)
diff --git a/modules/setting/cron.go b/modules/setting/cron.go
index 48298b453c..c544c6c228 100644
--- a/modules/setting/cron.go
+++ b/modules/setting/cron.go
@@ -119,6 +119,6 @@ var (
func newCron() {
if err := Cfg.Section("cron").MapTo(&Cron); err != nil {
- log.Fatal(4, "Failed to map Cron settings: %v", err)
+ log.Fatal("Failed to map Cron settings: %v", err)
}
}
diff --git a/modules/setting/git.go b/modules/setting/git.go
index 5d9701a435..0ad16fc81e 100644
--- a/modules/setting/git.go
+++ b/modules/setting/git.go
@@ -56,13 +56,13 @@ var (
func newGit() {
if err := Cfg.Section("git").MapTo(&Git); err != nil {
- log.Fatal(4, "Failed to map Git settings: %v", err)
+ log.Fatal("Failed to map Git settings: %v", err)
}
git.DefaultCommandExecutionTimeout = time.Duration(Git.Timeout.Default) * time.Second
binVersion, err := git.BinVersion()
if err != nil {
- log.Fatal(4, "Error retrieving git version: %v", err)
+ log.Fatal("Error retrieving git version: %v", err)
}
if version.Compare(binVersion, "2.9", ">=") {
diff --git a/modules/setting/log.go b/modules/setting/log.go
index 7b0832c0c8..c6b5b1a617 100644
--- a/modules/setting/log.go
+++ b/modules/setting/log.go
@@ -5,182 +5,287 @@
package setting
import (
- "fmt"
+ "encoding/json"
+ golog "log"
"os"
"path"
"path/filepath"
+ "runtime"
"strings"
"code.gitea.io/gitea/modules/log"
- "github.com/go-xorm/core"
+
+ ini "gopkg.in/ini.v1"
)
-var logLevels = map[string]string{
- "Trace": "0",
- "Debug": "1",
- "Info": "2",
- "Warn": "3",
- "Error": "4",
- "Critical": "5",
+type defaultLogOptions struct {
+ levelName string // LogLevel
+ flags string
+ filename string //path.Join(LogRootPath, "gitea.log")
+ bufferLength int64
+ disableConsole bool
}
-func getLogLevel(section string, key string, defaultValue string) string {
- validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
- return Cfg.Section(section).Key(key).In(defaultValue, validLevels)
+func newDefaultLogOptions() defaultLogOptions {
+ return defaultLogOptions{
+ levelName: LogLevel,
+ flags: "stdflags",
+ filename: filepath.Join(LogRootPath, "gitea.log"),
+ bufferLength: 10000,
+ disableConsole: false,
+ }
}
-func newLogService() {
- log.Info("Gitea v%s%s", AppVer, AppBuiltWith)
+// SubLogDescription describes a sublogger
+type SubLogDescription struct {
+ Name string
+ Provider string
+ Config string
+}
- LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
- LogConfigs = make([]string, len(LogModes))
+// LogDescription describes a named logger
+type LogDescription struct {
+ Name string
+ SubLogDescriptions []SubLogDescription
+}
- useConsole := false
- for i := 0; i < len(LogModes); i++ {
- LogModes[i] = strings.TrimSpace(LogModes[i])
- if LogModes[i] == "console" {
- useConsole = true
+func getLogLevel(section *ini.Section, key string, defaultValue string) string {
+ value := section.Key(key).MustString("info")
+ return log.FromString(value).String()
+}
+
+func getStacktraceLogLevel(section *ini.Section, key string, defaultValue string) string {
+ value := section.Key(key).MustString("none")
+ return log.FromString(value).String()
+}
+
+func generateLogConfig(sec *ini.Section, name string, defaults defaultLogOptions) (mode, jsonConfig, levelName string) {
+ levelName = getLogLevel(sec, "LEVEL", LogLevel)
+ level := log.FromString(levelName)
+ stacktraceLevelName := getStacktraceLogLevel(sec, "STACKTRACE_LEVEL", StacktraceLogLevel)
+ stacktraceLevel := log.FromString(stacktraceLevelName)
+ mode = name
+ keys := sec.Keys()
+ logPath := defaults.filename
+ flags := log.FlagsFromString(defaults.flags)
+ expression := ""
+ prefix := ""
+ for _, key := range keys {
+ switch key.Name() {
+ case "MODE":
+ mode = key.MustString(name)
+ case "FILE_NAME":
+ logPath = key.MustString(defaults.filename)
+ forcePathSeparator(logPath)
+ if !filepath.IsAbs(logPath) {
+ logPath = path.Join(LogRootPath, logPath)
+ }
+ case "FLAGS":
+ flags = log.FlagsFromString(key.MustString(defaults.flags))
+ case "EXPRESSION":
+ expression = key.MustString("")
+ case "PREFIX":
+ prefix = key.MustString("")
}
}
- if !useConsole {
- log.DelLogger("console")
+ logConfig := map[string]interface{}{
+ "level": level.String(),
+ "expression": expression,
+ "prefix": prefix,
+ "flags": flags,
+ "stacktraceLevel": stacktraceLevel.String(),
}
- for i, mode := range LogModes {
- sec, err := Cfg.GetSection("log." + mode)
- if err != nil {
- sec, _ = Cfg.NewSection("log." + mode)
+ // Generate log configuration.
+ switch mode {
+ case "console":
+ useStderr := sec.Key("STDERR").MustBool(false)
+ logConfig["stderr"] = useStderr
+ if useStderr {
+ logConfig["colorize"] = sec.Key("COLORIZE").MustBool(log.CanColorStderr)
+ } else {
+ logConfig["colorize"] = sec.Key("COLORIZE").MustBool(log.CanColorStdout)
}
- // Log level.
- levelName := getLogLevel("log."+mode, "LEVEL", LogLevel)
- level, ok := logLevels[levelName]
- if !ok {
- log.Fatal(4, "Unknown log level: %s", levelName)
+ case "file":
+ if err := os.MkdirAll(path.Dir(logPath), os.ModePerm); err != nil {
+ panic(err.Error())
}
- // Generate log configuration.
- switch mode {
- case "console":
- LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level)
- case "file":
- logPath := sec.Key("FILE_NAME").MustString(path.Join(LogRootPath, "gitea.log"))
- if err = os.MkdirAll(path.Dir(logPath), os.ModePerm); err != nil {
- panic(err.Error())
- }
+ logConfig["colorize"] = sec.Key("COLORIZE").MustBool(runtime.GOOS != "windows")
+ logConfig["filename"] = logPath
+ logConfig["rotate"] = sec.Key("LOG_ROTATE").MustBool(true)
+ logConfig["maxsize"] = 1 << uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28))
+ logConfig["daily"] = sec.Key("DAILY_ROTATE").MustBool(true)
+ logConfig["maxdays"] = sec.Key("MAX_DAYS").MustInt(7)
+ logConfig["compress"] = sec.Key("COMPRESS").MustBool(true)
+ logConfig["compressionLevel"] = sec.Key("COMPRESSION_LEVEL").MustInt(-1)
+ case "conn":
+ logConfig["reconnectOnMsg"] = sec.Key("RECONNECT_ON_MSG").MustBool()
+ logConfig["reconnect"] = sec.Key("RECONNECT").MustBool()
+ logConfig["net"] = sec.Key("PROTOCOL").In("tcp", []string{"tcp", "unix", "udp"})
+ logConfig["addr"] = sec.Key("ADDR").MustString(":7020")
+ case "smtp":
+ logConfig["username"] = sec.Key("USER").MustString("example@example.com")
+ logConfig["password"] = sec.Key("PASSWD").MustString("******")
+ logConfig["host"] = sec.Key("HOST").MustString("127.0.0.1:25")
+ logConfig["sendTos"] = sec.Key("RECEIVERS").MustString("[]")
+ logConfig["subject"] = sec.Key("SUBJECT").MustString("Diagnostic message from Gitea")
+ }
- LogConfigs[i] = fmt.Sprintf(
- `{"level":%s,"filename":"%s","rotate":%v,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
- logPath,
- sec.Key("LOG_ROTATE").MustBool(true),
- 1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
- sec.Key("DAILY_ROTATE").MustBool(true),
- sec.Key("MAX_DAYS").MustInt(7))
- case "conn":
- LogConfigs[i] = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
- sec.Key("RECONNECT_ON_MSG").MustBool(),
- sec.Key("RECONNECT").MustBool(),
- sec.Key("PROTOCOL").In("tcp", []string{"tcp", "unix", "udp"}),
- sec.Key("ADDR").MustString(":7020"))
- case "smtp":
- LogConfigs[i] = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":["%s"],"subject":"%s"}`, level,
- sec.Key("USER").MustString("example@example.com"),
- sec.Key("PASSWD").MustString("******"),
- sec.Key("HOST").MustString("127.0.0.1:25"),
- strings.Replace(sec.Key("RECEIVERS").MustString("example@example.com"), ",", "\",\"", -1),
- sec.Key("SUBJECT").MustString("Diagnostic message from serve"))
- case "database":
- LogConfigs[i] = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level,
- sec.Key("DRIVER").String(),
- sec.Key("CONN").String())
- }
+ logConfig["colorize"] = sec.Key("COLORIZE").MustBool(false)
- log.NewLogger(Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000), mode, LogConfigs[i])
- log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
+ byteConfig, err := json.Marshal(logConfig)
+ if err != nil {
+ log.Error("Failed to marshal log configuration: %v %v", logConfig, err)
+ return
}
+ jsonConfig = string(byteConfig)
+ return
}
-// NewXORMLogService initializes xorm logger service
-func NewXORMLogService(disableConsole bool) {
- logModes := strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
- var logConfigs string
- for _, mode := range logModes {
- mode = strings.TrimSpace(mode)
+func generateNamedLogger(key string, options defaultLogOptions) *LogDescription {
+ description := LogDescription{
+ Name: key,
+ }
+
+ sections := strings.Split(Cfg.Section("log").Key(strings.ToUpper(key)).MustString(""), ",")
- if disableConsole && mode == "console" {
+ //description.Configs = make([]string, len(description.Sections))
+
+ for i := 0; i < len(sections); i++ {
+ sections[i] = strings.TrimSpace(sections[i])
+ }
+
+ for _, name := range sections {
+ if len(name) == 0 || (name == "console" && options.disableConsole) {
continue
}
-
- sec, err := Cfg.GetSection("log." + mode)
+ sec, err := Cfg.GetSection("log." + name + "." + key)
if err != nil {
- sec, _ = Cfg.NewSection("log." + mode)
+ sec, _ = Cfg.NewSection("log." + name + "." + key)
}
- // Log level.
- levelName := getLogLevel("log."+mode, "LEVEL", LogLevel)
- level, ok := logLevels[levelName]
- if !ok {
- log.Fatal(4, "Unknown log level: %s", levelName)
- }
+ provider, config, levelName := generateLogConfig(sec, name, options)
- // Generate log configuration.
- switch mode {
- case "console":
- logConfigs = fmt.Sprintf(`{"level":%s}`, level)
- case "file":
- logPath := sec.Key("FILE_NAME").MustString(path.Join(LogRootPath, "xorm.log"))
- if err = os.MkdirAll(path.Dir(logPath), os.ModePerm); err != nil {
- panic(err.Error())
- }
- logPath = path.Join(filepath.Dir(logPath), "xorm.log")
-
- logConfigs = fmt.Sprintf(
- `{"level":%s,"filename":"%s","rotate":%v,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
- logPath,
- sec.Key("LOG_ROTATE").MustBool(true),
- 1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
- sec.Key("DAILY_ROTATE").MustBool(true),
- sec.Key("MAX_DAYS").MustInt(7))
- case "conn":
- logConfigs = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
- sec.Key("RECONNECT_ON_MSG").MustBool(),
- sec.Key("RECONNECT").MustBool(),
- sec.Key("PROTOCOL").In("tcp", []string{"tcp", "unix", "udp"}),
- sec.Key("ADDR").MustString(":7020"))
- case "smtp":
- logConfigs = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level,
- sec.Key("USER").MustString("example@example.com"),
- sec.Key("PASSWD").MustString("******"),
- sec.Key("HOST").MustString("127.0.0.1:25"),
- sec.Key("RECEIVERS").MustString("[]"),
- sec.Key("SUBJECT").MustString("Diagnostic message from serve"))
- case "database":
- logConfigs = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level,
- sec.Key("DRIVER").String(),
- sec.Key("CONN").String())
+ log.NewNamedLogger(key, options.bufferLength, name, provider, config)
+
+ description.SubLogDescriptions = append(description.SubLogDescriptions, SubLogDescription{
+ Name: name,
+ Provider: provider,
+ Config: config,
+ })
+ log.Info("%s Log: %s(%s:%s)", strings.Title(key), strings.Title(name), provider, levelName)
+ }
+
+ LogDescriptions[key] = &description
+
+ return &description
+}
+
+func newMacaronLogService() {
+ options := newDefaultLogOptions()
+ options.filename = filepath.Join(LogRootPath, "macaron.log")
+ options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
+
+ Cfg.Section("log").Key("MACARON").MustString("file")
+ if RedirectMacaronLog {
+ generateNamedLogger("macaron", options)
+ }
+}
+
+func newAccessLogService() {
+ EnableAccessLog = Cfg.Section("log").Key("ENABLE_ACCESS_LOG").MustBool(false)
+ AccessLogTemplate = Cfg.Section("log").Key("ACCESS_LOG_TEMPLATE").MustString(
+ `{{.Ctx.RemoteAddr}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}"`)
+ Cfg.Section("log").Key("ACCESS").MustString("file")
+ if EnableAccessLog {
+ options := newDefaultLogOptions()
+ options.filename = filepath.Join(LogRootPath, "access.log")
+ options.flags = "" // For the router we don't want any prefixed flags
+ options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
+ generateNamedLogger("access", options)
+ }
+}
+
+func newRouterLogService() {
+ Cfg.Section("log").Key("ROUTER").MustString("console")
+
+ if !DisableRouterLog && RedirectMacaronLog {
+ options := newDefaultLogOptions()
+ options.filename = filepath.Join(LogRootPath, "router.log")
+ options.flags = "date,time" // For the router we don't want any prefixed flags
+ options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
+ generateNamedLogger("router", options)
+ }
+}
+
+func newLogService() {
+ log.Info("Gitea v%s%s", AppVer, AppBuiltWith)
+
+ options := newDefaultLogOptions()
+ options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
+
+ description := LogDescription{
+ Name: log.DEFAULT,
+ }
+
+ sections := strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
+
+ useConsole := false
+ for i := 0; i < len(sections); i++ {
+ sections[i] = strings.TrimSpace(sections[i])
+ if sections[i] == "console" {
+ useConsole = true
}
+ }
- log.NewXORMLogger(Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000), mode, logConfigs)
- if !disableConsole {
- log.Info("XORM Log Mode: %s(%s)", strings.Title(mode), levelName)
+ if !useConsole {
+ log.DelLogger("console")
+ }
+
+ for _, name := range sections {
+ if len(name) == 0 {
+ continue
}
- var lvl core.LogLevel
- switch levelName {
- case "Trace", "Debug":
- lvl = core.LOG_DEBUG
- case "Info":
- lvl = core.LOG_INFO
- case "Warn":
- lvl = core.LOG_WARNING
- case "Error", "Critical":
- lvl = core.LOG_ERR
+ sec, err := Cfg.GetSection("log." + name)
+ if err != nil {
+ sec, _ = Cfg.NewSection("log." + name)
}
- log.XORMLogger.SetLevel(lvl)
+
+ provider, config, levelName := generateLogConfig(sec, name, options)
+ log.NewLogger(options.bufferLength, name, provider, config)
+ description.SubLogDescriptions = append(description.SubLogDescriptions, SubLogDescription{
+ Name: name,
+ Provider: provider,
+ Config: config,
+ })
+ log.Info("Gitea Log Mode: %s(%s:%s)", strings.Title(name), strings.Title(provider), levelName)
}
- if len(logConfigs) == 0 {
- log.DiscardXORMLogger()
+ LogDescriptions[log.DEFAULT] = &description
+
+ // Finally redirect the default golog to here
+ golog.SetFlags(0)
+ golog.SetPrefix("")
+ golog.SetOutput(log.NewLoggerAsWriter("INFO", log.GetLogger(log.DEFAULT)))
+}
+
+// NewXORMLogService initializes xorm logger service
+func NewXORMLogService(disableConsole bool) {
+ EnableXORMLog = Cfg.Section("log").Key("ENABLE_XORM_LOG").MustBool(true)
+ if EnableXORMLog {
+ options := newDefaultLogOptions()
+ options.filename = filepath.Join(LogRootPath, "xorm.log")
+ options.bufferLength = Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
+ options.disableConsole = disableConsole
+
+ Cfg.Section("log").Key("XORM").MustString(",")
+ generateNamedLogger("xorm", options)
+ log.InitXORMLogger(LogSQL)
+ } else {
+ log.InitXORMLogger(false)
}
}
diff --git a/modules/setting/mailer.go b/modules/setting/mailer.go
index 27c3d3a9f2..e627aef017 100644
--- a/modules/setting/mailer.go
+++ b/modules/setting/mailer.go
@@ -84,7 +84,7 @@ func newMailService() {
parsed, err := mail.ParseAddress(MailService.From)
if err != nil {
- log.Fatal(4, "Invalid mailer.FROM (%s): %v", MailService.From, err)
+ log.Fatal("Invalid mailer.FROM (%s): %v", MailService.From, err)
}
MailService.FromName = parsed.Name
MailService.FromEmail = parsed.Address
@@ -96,7 +96,7 @@ func newMailService() {
if MailService.MailerType == "sendmail" {
MailService.SendmailArgs, err = shellquote.Split(sec.Key("SENDMAIL_ARGS").String())
if err != nil {
- log.Error(4, "Failed to parse Sendmail args: %v", CustomConf, err)
+ log.Error("Failed to parse Sendmail args: %s with error %v", CustomConf, err)
}
}
diff --git a/modules/setting/repository.go b/modules/setting/repository.go
index 5880071286..f47661efdf 100644
--- a/modules/setting/repository.go
+++ b/modules/setting/repository.go
@@ -132,7 +132,7 @@ var (
func newRepository() {
homeDir, err := com.HomeDir()
if err != nil {
- log.Fatal(4, "Failed to get home directory: %v", err)
+ log.Fatal("Failed to get home directory: %v", err)
}
homeDir = strings.Replace(homeDir, "\\", "/", -1)
@@ -151,15 +151,15 @@ func newRepository() {
ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
- log.Fatal(4, "Failed to map Repository settings: %v", err)
+ log.Fatal("Failed to map Repository settings: %v", err)
} else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
- log.Fatal(4, "Failed to map Repository.Editor settings: %v", err)
+ log.Fatal("Failed to map Repository.Editor settings: %v", err)
} else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
- log.Fatal(4, "Failed to map Repository.Upload settings: %v", err)
+ log.Fatal("Failed to map Repository.Upload settings: %v", err)
} else if err = Cfg.Section("repository.local").MapTo(&Repository.Local); err != nil {
- log.Fatal(4, "Failed to map Repository.Local settings: %v", err)
+ log.Fatal("Failed to map Repository.Local settings: %v", err)
} else if err = Cfg.Section("repository.pull-request").MapTo(&Repository.PullRequest); err != nil {
- log.Fatal(4, "Failed to map Repository.PullRequest settings: %v", err)
+ log.Fatal("Failed to map Repository.PullRequest settings: %v", err)
}
if !filepath.IsAbs(Repository.Upload.TempPath) {
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 95fca20b11..b6c5740024 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -7,6 +7,7 @@ package setting
import (
"encoding/base64"
+ "fmt"
"io"
"io/ioutil"
"net"
@@ -15,7 +16,6 @@ import (
"os/exec"
"path"
"path/filepath"
- "runtime"
"strconv"
"strings"
"time"
@@ -90,7 +90,6 @@ var (
RedirectOtherPort bool
PortToRedirect string
OfflineMode bool
- DisableRouterLog bool
CertFile string
KeyFile string
StaticRootPath string
@@ -259,10 +258,16 @@ var (
// Log settings
LogLevel string
+ StacktraceLogLevel string
LogRootPath string
- LogModes []string
- LogConfigs []string
+ LogDescriptions = make(map[string]*LogDescription)
RedirectMacaronLog bool
+ DisableRouterLog bool
+ RouterLogLevel log.Level
+ RouterLogMode string
+ EnableAccessLog bool
+ AccessLogTemplate string
+ EnableXORMLog bool
// Attachment settings
AttachmentPath string
@@ -398,19 +403,19 @@ func getWorkPath(appPath string) string {
}
func init() {
- IsWindows = runtime.GOOS == "windows"
- log.NewLogger(0, "console", `{"level": 0}`)
+ // We can rely on log.CanColorStdout being set properly because modules/log/console_windows.go comes before modules/setting/setting.go lexicographically
+ log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "trace", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
var err error
if AppPath, err = getAppPath(); err != nil {
- log.Fatal(4, "Failed to get app path: %v", err)
+ log.Fatal("Failed to get app path: %v", err)
}
AppWorkPath = getWorkPath(AppPath)
}
func forcePathSeparator(path string) {
if strings.Contains(path, "\\") {
- log.Fatal(4, "Do not use '\\' or '\\\\' in paths, instead, please use '/' in all places")
+ log.Fatal("Do not use '\\' or '\\\\' in paths, instead, please use '/' in all places")
}
}
@@ -430,16 +435,16 @@ func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
func createPIDFile(pidPath string) {
currentPid := os.Getpid()
if err := os.MkdirAll(filepath.Dir(pidPath), os.ModePerm); err != nil {
- log.Fatal(4, "Failed to create PID folder: %v", err)
+ log.Fatal("Failed to create PID folder: %v", err)
}
file, err := os.Create(pidPath)
if err != nil {
- log.Fatal(4, "Failed to create PID file: %v", err)
+ log.Fatal("Failed to create PID file: %v", err)
}
defer file.Close()
if _, err := file.WriteString(strconv.FormatInt(int64(currentPid), 10)); err != nil {
- log.Fatal(4, "Failed to write PID information: %v", err)
+ log.Fatal("Failed to write PID information: %v", err)
}
}
@@ -451,12 +456,12 @@ func CheckLFSVersion() {
binVersion, err := git.BinVersion()
if err != nil {
- log.Fatal(4, "Error retrieving git version: %v", err)
+ log.Fatal("Error retrieving git version: %v", err)
}
if !version.Compare(binVersion, "2.1.2", ">=") {
LFS.StartServer = false
- log.Error(4, "LFS server support needs at least Git v2.1.2")
+ log.Error("LFS server support needs at least Git v2.1.2")
} else {
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "filter.lfs.required=",
"-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=")
@@ -488,7 +493,7 @@ func NewContext() {
if com.IsFile(CustomConf) {
if err := Cfg.Append(CustomConf); err != nil {
- log.Fatal(4, "Failed to load custom conf '%s': %v", CustomConf, err)
+ log.Fatal("Failed to load custom conf '%s': %v", CustomConf, err)
}
} else {
log.Warn("Custom config '%s' not found, ignore this if you're running first time", CustomConf)
@@ -497,14 +502,16 @@ func NewContext() {
homeDir, err := com.HomeDir()
if err != nil {
- log.Fatal(4, "Failed to get home directory: %v", err)
+ log.Fatal("Failed to get home directory: %v", err)
}
homeDir = strings.Replace(homeDir, "\\", "/", -1)
- LogLevel = getLogLevel("log", "LEVEL", "Info")
+ LogLevel = getLogLevel(Cfg.Section("log"), "LEVEL", "Info")
+ StacktraceLogLevel = getStacktraceLogLevel(Cfg.Section("log"), "STACKTRACE_LEVEL", "None")
LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(AppWorkPath, "log"))
forcePathSeparator(LogRootPath)
RedirectMacaronLog = Cfg.Section("log").Key("REDIRECT_MACARON_LOG").MustBool(false)
+ RouterLogLevel = log.FromString(Cfg.Section("log").Key("ROUTER_LOG_LEVEL").MustString("Info"))
sec := Cfg.Section("server")
AppName = Cfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea")
@@ -521,7 +528,7 @@ func NewContext() {
UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32)
if err != nil || UnixSocketPermissionParsed > 0777 {
- log.Fatal(4, "Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
+ log.Fatal("Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
}
UnixSocketPermission = uint32(UnixSocketPermissionParsed)
}
@@ -547,7 +554,7 @@ func NewContext() {
// Check if has app suburl.
url, err := url.Parse(AppURL)
if err != nil {
- log.Fatal(4, "Invalid ROOT_URL '%s': %s", AppURL, err)
+ log.Fatal("Invalid ROOT_URL '%s': %s", AppURL, err)
}
// Suburl should start with '/' and end without '/', such as '/{subpath}'.
// This value is empty if site does not have sub-url.
@@ -616,7 +623,7 @@ func NewContext() {
}
SSH.KeyTestPath = os.TempDir()
if err = Cfg.Section("server").MapTo(&SSH); err != nil {
- log.Fatal(4, "Failed to map SSH settings: %v", err)
+ log.Fatal("Failed to map SSH settings: %v", err)
}
SSH.KeygenPath = sec.Key("SSH_KEYGEN_PATH").MustString("ssh-keygen")
@@ -630,9 +637,9 @@ func NewContext() {
if !SSH.Disabled && !SSH.StartBuiltinServer {
if err := os.MkdirAll(SSH.RootPath, 0700); err != nil {
- log.Fatal(4, "Failed to create '%s': %v", SSH.RootPath, err)
+ log.Fatal("Failed to create '%s': %v", SSH.RootPath, err)
} else if err = os.MkdirAll(SSH.KeyTestPath, 0644); err != nil {
- log.Fatal(4, "Failed to create '%s': %v", SSH.KeyTestPath, err)
+ log.Fatal("Failed to create '%s': %v", SSH.KeyTestPath, err)
}
}
@@ -650,7 +657,7 @@ func NewContext() {
sec = Cfg.Section("server")
if err = sec.MapTo(&LFS); err != nil {
- log.Fatal(4, "Failed to map LFS settings: %v", err)
+ log.Fatal("Failed to map LFS settings: %v", err)
}
LFS.ContentPath = sec.Key("LFS_CONTENT_PATH").MustString(filepath.Join(AppDataPath, "lfs"))
if !filepath.IsAbs(LFS.ContentPath) {
@@ -661,7 +668,7 @@ func NewContext() {
if LFS.StartServer {
if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {
- log.Fatal(4, "Failed to create '%s': %v", LFS.ContentPath, err)
+ log.Fatal("Failed to create '%s': %v", LFS.ContentPath, err)
}
LFS.JWTSecretBytes = make([]byte, 32)
@@ -670,7 +677,7 @@ func NewContext() {
if err != nil || n != 32 {
LFS.JWTSecretBase64, err = generate.NewJwtSecret()
if err != nil {
- log.Fatal(4, "Error generating JWT Secret for custom config: %v", err)
+ log.Fatal("Error generating JWT Secret for custom config: %v", err)
return
}
@@ -679,24 +686,24 @@ func NewContext() {
if com.IsFile(CustomConf) {
// Keeps custom settings if there is already something.
if err := cfg.Append(CustomConf); err != nil {
- log.Error(4, "Failed to load custom conf '%s': %v", CustomConf, err)
+ log.Error("Failed to load custom conf '%s': %v", CustomConf, err)
}
}
cfg.Section("server").Key("LFS_JWT_SECRET").SetValue(LFS.JWTSecretBase64)
if err := os.MkdirAll(filepath.Dir(CustomConf), os.ModePerm); err != nil {
- log.Fatal(4, "Failed to create '%s': %v", CustomConf, err)
+ log.Fatal("Failed to create '%s': %v", CustomConf, err)
}
if err := cfg.SaveTo(CustomConf); err != nil {
- log.Fatal(4, "Error saving generated JWT Secret to custom config: %v", err)
+ log.Fatal("Error saving generated JWT Secret to custom config: %v", err)
return
}
}
}
if err = Cfg.Section("oauth2").MapTo(&OAuth2); err != nil {
- log.Fatal(4, "Failed to OAuth2 settings: %v", err)
+ log.Fatal("Failed to OAuth2 settings: %v", err)
return
}
@@ -707,24 +714,24 @@ func NewContext() {
if err != nil || n != 32 {
OAuth2.JWTSecretBase64, err = generate.NewJwtSecret()
if err != nil {
- log.Fatal(4, "error generating JWT secret: %v", err)
+ log.Fatal("error generating JWT secret: %v", err)
return
}
cfg := ini.Empty()
if com.IsFile(CustomConf) {
if err := cfg.Append(CustomConf); err != nil {
- log.Error(4, "failed to load custom conf %s: %v", CustomConf, err)
+ log.Error("failed to load custom conf %s: %v", CustomConf, err)
return
}
}
cfg.Section("oauth2").Key("JWT_SECRET").SetValue(OAuth2.JWTSecretBase64)
if err := os.MkdirAll(filepath.Dir(CustomConf), os.ModePerm); err != nil {
- log.Fatal(4, "failed to create '%s': %v", CustomConf, err)
+ log.Fatal("failed to create '%s': %v", CustomConf, err)
return
}
if err := cfg.SaveTo(CustomConf); err != nil {
- log.Fatal(4, "error saving generating JWT secret to custom config: %v", err)
+ log.Fatal("error saving generating JWT secret to custom config: %v", err)
return
}
}
@@ -780,7 +787,7 @@ func NewContext() {
TimeFormat = TimeFormatKey
TestTimeFormat, _ := time.Parse(TimeFormat, TimeFormat)
if TestTimeFormat.Format(time.RFC3339) != "2006-01-02T15:04:05Z" {
- log.Fatal(4, "Can't create time properly, please check your time format has 2006, 01, 02, 15, 04 and 05")
+ log.Fatal("Can't create time properly, please check your time format has 2006, 01, 02, 15, 04 and 05")
}
log.Trace("Custom TimeFormat: %s", TimeFormat)
}
@@ -790,7 +797,7 @@ func NewContext() {
if InstallLock {
currentUser, match := IsRunUserMatchCurrentUser(RunUser)
if !match {
- log.Fatal(4, "Expect user '%s' but current user is: %s", RunUser, currentUser)
+ log.Fatal("Expect user '%s' but current user is: %s", RunUser, currentUser)
}
}
@@ -828,7 +835,7 @@ func NewContext() {
if EnableFederatedAvatar || !DisableGravatar {
GravatarSourceURL, err = url.Parse(GravatarSource)
if err != nil {
- log.Fatal(4, "Failed to parse Gravatar URL(%s): %v",
+ log.Fatal("Failed to parse Gravatar URL(%s): %v",
GravatarSource, err)
}
}
@@ -845,15 +852,15 @@ func NewContext() {
}
if err = Cfg.Section("ui").MapTo(&UI); err != nil {
- log.Fatal(4, "Failed to map UI settings: %v", err)
+ log.Fatal("Failed to map UI settings: %v", err)
} else if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
- log.Fatal(4, "Failed to map Markdown settings: %v", err)
+ log.Fatal("Failed to map Markdown settings: %v", err)
} else if err = Cfg.Section("admin").MapTo(&Admin); err != nil {
- log.Fatal(4, "Fail to map Admin settings: %v", err)
+ log.Fatal("Fail to map Admin settings: %v", err)
} else if err = Cfg.Section("api").MapTo(&API); err != nil {
- log.Fatal(4, "Failed to map API settings: %v", err)
+ log.Fatal("Failed to map API settings: %v", err)
} else if err = Cfg.Section("metrics").MapTo(&Metrics); err != nil {
- log.Fatal(4, "Failed to map Metrics settings: %v", err)
+ log.Fatal("Failed to map Metrics settings: %v", err)
}
newCron()
@@ -909,35 +916,35 @@ func loadInternalToken(sec *ini.Section) string {
}
tempURI, err := url.Parse(uri)
if err != nil {
- log.Fatal(4, "Failed to parse INTERNAL_TOKEN_URI (%s): %v", uri, err)
+ log.Fatal("Failed to parse INTERNAL_TOKEN_URI (%s): %v", uri, err)
}
switch tempURI.Scheme {
case "file":
fp, err := os.OpenFile(tempURI.RequestURI(), os.O_RDWR, 0600)
if err != nil {
- log.Fatal(4, "Failed to open InternalTokenURI (%s): %v", uri, err)
+ log.Fatal("Failed to open InternalTokenURI (%s): %v", uri, err)
}
defer fp.Close()
buf, err := ioutil.ReadAll(fp)
if err != nil {
- log.Fatal(4, "Failed to read InternalTokenURI (%s): %v", uri, err)
+ log.Fatal("Failed to read InternalTokenURI (%s): %v", uri, err)
}
// No token in the file, generate one and store it.
if len(buf) == 0 {
token, err := generate.NewInternalToken()
if err != nil {
- log.Fatal(4, "Error generate internal token: %v", err)
+ log.Fatal("Error generate internal token: %v", err)
}
if _, err := io.WriteString(fp, token); err != nil {
- log.Fatal(4, "Error writing to InternalTokenURI (%s): %v", uri, err)
+ log.Fatal("Error writing to InternalTokenURI (%s): %v", uri, err)
}
return token
}
return string(buf)
default:
- log.Fatal(4, "Unsupported URI-Scheme %q (INTERNAL_TOKEN_URI = %q)", tempURI.Scheme, uri)
+ log.Fatal("Unsupported URI-Scheme %q (INTERNAL_TOKEN_URI = %q)", tempURI.Scheme, uri)
}
return ""
}
@@ -948,7 +955,7 @@ func loadOrGenerateInternalToken(sec *ini.Section) string {
if len(token) == 0 {
token, err = generate.NewInternalToken()
if err != nil {
- log.Fatal(4, "Error generate internal token: %v", err)
+ log.Fatal("Error generate internal token: %v", err)
}
// Save secret
@@ -956,17 +963,17 @@ func loadOrGenerateInternalToken(sec *ini.Section) string {
if com.IsFile(CustomConf) {
// Keeps custom settings if there is already something.
if err := cfgSave.Append(CustomConf); err != nil {
- log.Error(4, "Failed to load custom conf '%s': %v", CustomConf, err)
+ log.Error("Failed to load custom conf '%s': %v", CustomConf, err)
}
}
cfgSave.Section("security").Key("INTERNAL_TOKEN").SetValue(token)
if err := os.MkdirAll(filepath.Dir(CustomConf), os.ModePerm); err != nil {
- log.Fatal(4, "Failed to create '%s': %v", CustomConf, err)
+ log.Fatal("Failed to create '%s': %v", CustomConf, err)
}
if err := cfgSave.SaveTo(CustomConf); err != nil {
- log.Fatal(4, "Error saving generated INTERNAL_TOKEN to custom config: %v", err)
+ log.Fatal("Error saving generated INTERNAL_TOKEN to custom config: %v", err)
}
}
return token
@@ -976,6 +983,9 @@ func loadOrGenerateInternalToken(sec *ini.Section) string {
func NewServices() {
newService()
newLogService()
+ newMacaronLogService()
+ newAccessLogService()
+ newRouterLogService()
NewXORMLogService(false)
newCacheService()
newSessionService()