github.com/RajatVaryani/mattermost-server@v5.11.1+incompatible/mlog/global.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package mlog 5 6 import ( 7 "go.uber.org/zap" 8 "go.uber.org/zap/zapcore" 9 ) 10 11 var globalLogger *Logger 12 13 func InitGlobalLogger(logger *Logger) { 14 glob := *logger 15 glob.zap = glob.zap.WithOptions(zap.AddCallerSkip(1)) 16 globalLogger = &glob 17 Debug = globalLogger.Debug 18 Info = globalLogger.Info 19 Warn = globalLogger.Warn 20 Error = globalLogger.Error 21 Critical = globalLogger.Critical 22 } 23 24 func RedirectStdLog(logger *Logger) { 25 zap.RedirectStdLogAt(logger.zap.With(zap.String("source", "stdlog")).WithOptions(zap.AddCallerSkip(-2)), zapcore.ErrorLevel) 26 } 27 28 type LogFunc func(string, ...Field) 29 30 // DON'T USE THIS Modify the level on the app logger 31 func GloballyDisableDebugLogForTest() { 32 globalLogger.consoleLevel.SetLevel(zapcore.ErrorLevel) 33 } 34 35 // DON'T USE THIS Modify the level on the app logger 36 func GloballyEnableDebugLogForTest() { 37 globalLogger.consoleLevel.SetLevel(zapcore.DebugLevel) 38 } 39 40 var Debug LogFunc = defaultDebugLog 41 var Info LogFunc = defaultInfoLog 42 var Warn LogFunc = defaultWarnLog 43 var Error LogFunc = defaultErrorLog 44 var Critical LogFunc = defaultCriticalLog