summaryrefslogtreecommitdiffstats
path: root/mlog/log.go
diff options
context:
space:
mode:
Diffstat (limited to 'mlog/log.go')
-rw-r--r--mlog/log.go27
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...)
}