summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/log/log.go42
-rw-r--r--modules/setting/setting.go10
2 files changed, 48 insertions, 4 deletions
diff --git a/modules/log/log.go b/modules/log/log.go
index 36038d3d0c..98a8014b51 100644
--- a/modules/log/log.go
+++ b/modules/log/log.go
@@ -154,6 +154,48 @@ type LoggerInterface interface {
type loggerType func() LoggerInterface
+// LoggerAsWriter is a io.Writer shim around the gitea log
+type LoggerAsWriter struct {
+ level int
+}
+
+// NewLoggerAsWriter creates a Writer representation of the logger with setable log level
+func NewLoggerAsWriter(level string) *LoggerAsWriter {
+ l := &LoggerAsWriter{}
+ switch strings.ToUpper(level) {
+ case "TRACE":
+ l.level = TRACE
+ case "DEBUG":
+ l.level = DEBUG
+ case "INFO":
+ l.level = INFO
+ case "WARN":
+ l.level = WARN
+ case "ERROR":
+ l.level = ERROR
+ case "CRITICAL":
+ l.level = CRITICAL
+ case "FATAL":
+ l.level = FATAL
+ default:
+ l.level = INFO
+ }
+ return l
+}
+
+// Write implements the io.Writer interface to allow spoofing of macaron
+func (l *LoggerAsWriter) Write(p []byte) (int, error) {
+ l.Log(string(p))
+ return len(p), nil
+}
+
+// Log takes a given string and logs it at the set log-level
+func (l *LoggerAsWriter) Log(msg string) {
+ for _, logger := range loggers {
+ logger.writerMsg(0, l.level, msg)
+ }
+}
+
var adapters = make(map[string]loggerType)
// Register registers given logger provider to adapters.
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 77f0725d00..0859b81c40 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -393,10 +393,11 @@ var (
LibravatarService *libravatar.Libravatar
// Log settings
- LogLevel string
- LogRootPath string
- LogModes []string
- LogConfigs []string
+ LogLevel string
+ LogRootPath string
+ LogModes []string
+ LogConfigs []string
+ RedirectMacaronLog bool
// Attachment settings
AttachmentPath string
@@ -767,6 +768,7 @@ func NewContext() {
LogLevel = getLogLevel("log", "LEVEL", "Info")
LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(AppWorkPath, "log"))
forcePathSeparator(LogRootPath)
+ RedirectMacaronLog = Cfg.Section("log").Key("REDIRECT_MACARON_LOG").MustBool(false)
sec := Cfg.Section("server")
AppName = Cfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea")