diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-07-03 09:58:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-03 09:58:28 -0700 |
commit | 83a3ac089cff0d05559e6ba5c2c60b09f5cae176 (patch) | |
tree | 51cc53c0a77cf455cf9d700a453b6d57f1604fdb /mlog/log.go | |
parent | 3848cb7e79e019e2f0878d6e2377ad36b3c7ca43 (diff) | |
download | chat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.tar.gz chat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.tar.bz2 chat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.zip |
MM-11029 Adding plugin logging functionality. (#9034)
* Capturing stdout, stderr of plugins in logs.
* Cleanup go-plugin debug logs.
* Adding logging to plugin API
* Generating mocks.
* godoc convention
Diffstat (limited to 'mlog/log.go')
-rw-r--r-- | mlog/log.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/mlog/log.go b/mlog/log.go index 780e1ad57..e3bc38d83 100644 --- a/mlog/log.go +++ b/mlog/log.go @@ -4,6 +4,7 @@ package mlog import ( + "io" "log" "os" @@ -101,7 +102,7 @@ func NewLogger(config *LoggerConfiguration) *Logger { combinedCore := zapcore.NewTee(cores...) logger.zap = zap.New(combinedCore, - zap.AddCallerSkip(2), + zap.AddCallerSkip(1), zap.AddCaller(), ) @@ -127,6 +128,30 @@ func (l *Logger) StdLog(fields ...Field) *log.Logger { return zap.NewStdLog(l.With(fields...).zap.WithOptions(getStdLogOption())) } +// StdLogWriter returns a writer that can be hooked up to the output of a golang standard logger +// anything written will be interpreted as log entries accordingly +func (l *Logger) StdLogWriter() io.Writer { + newLogger := *l + newLogger.zap = newLogger.zap.WithOptions(zap.AddCallerSkip(4), getStdLogOption()) + f := newLogger.Info + return &loggerWriter{f} +} + +func (l *Logger) WithCallerSkip(skip int) *Logger { + newlogger := *l + newlogger.zap = newlogger.zap.WithOptions(zap.AddCallerSkip(skip)) + return &newlogger +} + +// Made for the plugin interface, wraps mlog in a simpler interface +// at the cost of performance +func (l *Logger) Sugar() *SugarLogger { + return &SugarLogger{ + wrappedLogger: l, + zapSugar: l.zap.Sugar(), + } +} + func (l *Logger) Debug(message string, fields ...Field) { l.zap.Debug(message, fields...) } |