diff options
author | zeripath <art27@cantab.net> | 2020-10-31 05:36:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-31 01:36:46 -0400 |
commit | 47dd1cb7ae8591b4c63b68371cc1922c0aa5f98e (patch) | |
tree | 11b9670fc2655642b7b82873ca8b5a48a5e607ff /modules/log/log.go | |
parent | ffc8ce7baef0715bdc2d04cfc1e18379426a1e89 (diff) | |
download | gitea-47dd1cb7ae8591b4c63b68371cc1922c0aa5f98e.tar.gz gitea-47dd1cb7ae8591b4c63b68371cc1922c0aa5f98e.zip |
Refactor Logger (#13294)
Refactor Logger to make a logger interface and make it possible to
wrap loggers for specific purposes.
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/log/log.go')
-rw-r--r-- | modules/log/log.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/modules/log/log.go b/modules/log/log.go index 2a35b5752c..16a6efb75b 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -16,16 +16,16 @@ type loggerMap struct { sync.Map } -func (m *loggerMap) Load(k string) (*Logger, bool) { +func (m *loggerMap) Load(k string) (*MultiChannelledLogger, bool) { v, ok := m.Map.Load(k) if !ok { return nil, false } - l, ok := v.(*Logger) + l, ok := v.(*MultiChannelledLogger) return l, ok } -func (m *loggerMap) Store(k string, v *Logger) { +func (m *loggerMap) Store(k string, v *MultiChannelledLogger) { m.Map.Store(k, v) } @@ -42,7 +42,7 @@ var ( ) // NewLogger create a logger for the default logger -func NewLogger(bufLen int64, name, provider, config string) *Logger { +func NewLogger(bufLen int64, name, provider, config string) *MultiChannelledLogger { err := NewNamedLogger(DEFAULT, bufLen, name, provider, config) if err != nil { CriticalWithSkip(1, "Unable to create default logger: %v", err) @@ -83,7 +83,7 @@ func DelLogger(name string) error { } // GetLogger returns either a named logger or the default logger -func GetLogger(name string) *Logger { +func GetLogger(name string) *MultiChannelledLogger { logger, ok := NamedLoggers.Load(name) if ok { return logger @@ -196,7 +196,7 @@ func IsFatal() bool { // Pause pauses all the loggers func Pause() { NamedLoggers.Range(func(key, value interface{}) bool { - logger := value.(*Logger) + logger := value.(*MultiChannelledLogger) logger.Pause() logger.Flush() return true @@ -206,7 +206,7 @@ func Pause() { // Resume resumes all the loggers func Resume() { NamedLoggers.Range(func(key, value interface{}) bool { - logger := value.(*Logger) + logger := value.(*MultiChannelledLogger) logger.Resume() return true }) @@ -216,7 +216,7 @@ func Resume() { func ReleaseReopen() error { var accumulatedErr error NamedLoggers.Range(func(key, value interface{}) bool { - logger := value.(*Logger) + logger := value.(*MultiChannelledLogger) if err := logger.ReleaseReopen(); err != nil { if accumulatedErr == nil { accumulatedErr = fmt.Errorf("Error reopening %s: %v", key.(string), err) @@ -250,15 +250,15 @@ func Log(skip int, level Level, format string, v ...interface{}) { // LoggerAsWriter is a io.Writer shim around the gitea log type LoggerAsWriter struct { - ourLoggers []*Logger + ourLoggers []*MultiChannelledLogger level Level } // NewLoggerAsWriter creates a Writer representation of the logger with setable log level -func NewLoggerAsWriter(level string, ourLoggers ...*Logger) *LoggerAsWriter { +func NewLoggerAsWriter(level string, ourLoggers ...*MultiChannelledLogger) *LoggerAsWriter { if len(ourLoggers) == 0 { l, _ := NamedLoggers.Load(DEFAULT) - ourLoggers = []*Logger{l} + ourLoggers = []*MultiChannelledLogger{l} } l := &LoggerAsWriter{ ourLoggers: ourLoggers, |