github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+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 globalLogger = logger 15 Debug = globalLogger.Debug 16 Info = globalLogger.Info 17 Warn = globalLogger.Warn 18 Error = globalLogger.Error 19 Critical = globalLogger.Critical 20 } 21 22 func RedirectStdLog(logger *Logger) { 23 zap.RedirectStdLogAt(logger.zap.With(zap.String("source", "stdlog")), zapcore.ErrorLevel) 24 } 25 26 type LogFunc func(string, ...Field) 27 28 // DON'T USE THIS Modify the level on the app logger 29 func GloballyDisableDebugLogForTest() { 30 globalLogger.consoleLevel.SetLevel(zapcore.ErrorLevel) 31 } 32 33 // DON'T USE THIS Modify the level on the app logger 34 func GloballyEnableDebugLogForTest() { 35 globalLogger.consoleLevel.SetLevel(zapcore.DebugLevel) 36 } 37 38 var Debug LogFunc = defaultDebugLog 39 var Info LogFunc = defaultInfoLog 40 var Warn LogFunc = defaultWarnLog 41 var Error LogFunc = defaultErrorLog 42 var Critical LogFunc = defaultCriticalLog