summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/mattermost-server/v5/mlog/global.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-10-19 23:40:00 +0200
committerGitHub <noreply@github.com>2020-10-19 23:40:00 +0200
commit075a84427f6332aab707d283ad770d69f8816032 (patch)
tree0ff9f56a057919f3fe968e57f6f0b1c0d1f85078 /vendor/github.com/mattermost/mattermost-server/v5/mlog/global.go
parent950f2759bd2b20aa0bdedc3dc9a74d0dafb606d8 (diff)
downloadmatterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.tar.gz
matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.tar.bz2
matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.zip
Update vendor (#1265)
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/mlog/global.go')
-rw-r--r--vendor/github.com/mattermost/mattermost-server/v5/mlog/global.go53
1 files changed, 52 insertions, 1 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/mlog/global.go b/vendor/github.com/mattermost/mattermost-server/v5/mlog/global.go
index 73f40b2f..2986d92d 100644
--- a/vendor/github.com/mattermost/mattermost-server/v5/mlog/global.go
+++ b/vendor/github.com/mattermost/mattermost-server/v5/mlog/global.go
@@ -4,6 +4,11 @@
package mlog
import (
+ "context"
+ "log"
+ "sync/atomic"
+
+ "github.com/mattermost/logr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
@@ -11,6 +16,10 @@ import (
var globalLogger *Logger
func InitGlobalLogger(logger *Logger) {
+ // Clean up previous instance.
+ if globalLogger != nil && globalLogger.logrLogger != nil {
+ globalLogger.logrLogger.Logr().Shutdown()
+ }
glob := *logger
glob.zap = glob.zap.WithOptions(zap.AddCallerSkip(1))
globalLogger = &glob
@@ -19,13 +28,46 @@ func InitGlobalLogger(logger *Logger) {
Warn = globalLogger.Warn
Error = globalLogger.Error
Critical = globalLogger.Critical
+ Log = globalLogger.Log
+ LogM = globalLogger.LogM
+ Flush = globalLogger.Flush
+ ConfigAdvancedLogging = globalLogger.ConfigAdvancedLogging
+ ShutdownAdvancedLogging = globalLogger.ShutdownAdvancedLogging
+ AddTarget = globalLogger.AddTarget
+ RemoveTargets = globalLogger.RemoveTargets
+ EnableMetrics = globalLogger.EnableMetrics
+}
+
+// logWriterFunc provides access to mlog via io.Writer, so the standard logger
+// can be redirected to use mlog and whatever targets are defined.
+type logWriterFunc func([]byte) (int, error)
+
+func (lw logWriterFunc) Write(p []byte) (int, error) {
+ return lw(p)
}
func RedirectStdLog(logger *Logger) {
- zap.RedirectStdLogAt(logger.zap.With(zap.String("source", "stdlog")).WithOptions(zap.AddCallerSkip(-2)), zapcore.ErrorLevel)
+ if atomic.LoadInt32(&disableZap) == 0 {
+ zap.RedirectStdLogAt(logger.zap.With(zap.String("source", "stdlog")).WithOptions(zap.AddCallerSkip(-2)), zapcore.ErrorLevel)
+ return
+ }
+
+ writer := func(p []byte) (int, error) {
+ Log(LvlStdLog, string(p))
+ return len(p), nil
+ }
+ log.SetOutput(logWriterFunc(writer))
}
type LogFunc func(string, ...Field)
+type LogFuncCustom func(LogLevel, string, ...Field)
+type LogFuncCustomMulti func([]LogLevel, string, ...Field)
+type FlushFunc func(context.Context) error
+type ConfigFunc func(cfg LogTargetCfg) error
+type ShutdownFunc func(context.Context) error
+type AddTargetFunc func(...logr.Target) error
+type RemoveTargetsFunc func(context.Context, func(TargetInfo) bool) error
+type EnableMetricsFunc func(logr.MetricsCollector) error
// DON'T USE THIS Modify the level on the app logger
func GloballyDisableDebugLogForTest() {
@@ -42,3 +84,12 @@ var Info LogFunc = defaultInfoLog
var Warn LogFunc = defaultWarnLog
var Error LogFunc = defaultErrorLog
var Critical LogFunc = defaultCriticalLog
+var Log LogFuncCustom = defaultCustomLog
+var LogM LogFuncCustomMulti = defaultCustomMultiLog
+var Flush FlushFunc = defaultFlush
+
+var ConfigAdvancedLogging ConfigFunc = defaultAdvancedConfig
+var ShutdownAdvancedLogging ShutdownFunc = defaultAdvancedShutdown
+var AddTarget AddTargetFunc = defaultAddTarget
+var RemoveTargets RemoveTargetsFunc = defaultRemoveTargets
+var EnableMetrics EnableMetricsFunc = defaultEnableMetrics