diff options
author | JoramWilander <jwawilander@gmail.com> | 2018-07-10 15:01:43 -0400 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2018-07-10 15:01:43 -0400 |
commit | 6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005 (patch) | |
tree | 5564a47257bf6e85aaef711980c5b0fcb4d07dcc /mlog/log.go | |
parent | c042ffa460296587579aff54b157a5109e022f7e (diff) | |
parent | 1e1a5e5e85240f25c4faddcb24c5a29a915fe6e4 (diff) | |
download | chat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.tar.gz chat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.tar.bz2 chat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.zip |
Merge branch 'plugins-2'
Diffstat (limited to 'mlog/log.go')
-rw-r--r-- | mlog/log.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/mlog/log.go b/mlog/log.go index c3261459b..e3bc38d83 100644 --- a/mlog/log.go +++ b/mlog/log.go @@ -4,6 +4,7 @@ package mlog import ( + "io" "log" "os" @@ -28,9 +29,11 @@ type Field = zapcore.Field var Int64 = zap.Int64 var Int = zap.Int +var Uint32 = zap.Uint32 var String = zap.String var Any = zap.Any var Err = zap.Error +var Bool = zap.Bool type LoggerConfiguration struct { EnableConsole bool @@ -99,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(), ) @@ -125,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...) } |