diff --git a/logger.go b/logger.go index 668568f..f49d85d 100644 --- a/logger.go +++ b/logger.go @@ -276,6 +276,13 @@ func (l *Logger) SetCallerFormatter(f CallerFormatter) { l.callerFormatter = f } +// SetCallerOffset sets the caller offset. +func (l *Logger) SetCallerOffset(offset int) { + l.mu.Lock() + defer l.mu.Unlock() + l.callerOffset = offset +} + // With returns a new logger with the given keyvals added. func (l *Logger) With(keyvals ...interface{}) *Logger { sl := *l diff --git a/options.go b/options.go index fc63ecc..73115bd 100644 --- a/options.go +++ b/options.go @@ -52,8 +52,11 @@ type Options struct { ReportCaller bool // CallerFormatter is the caller format for the logger. The default is CallerShort. CallerFormatter CallerFormatter + // CallerOffset is the caller format for the logger. The default is 0. + CallerOffset int // Fields is the fields for the logger. The default is no fields. Fields []interface{} // Formatter is the formatter for the logger. The default is TextFormatter. Formatter Formatter + } diff --git a/pkg.go b/pkg.go index 9c4aa64..2b35b4a 100644 --- a/pkg.go +++ b/pkg.go @@ -48,6 +48,7 @@ func NewWithOptions(w io.Writer, o Options) *Logger { formatter: o.Formatter, fields: o.Fields, callerFormatter: o.CallerFormatter, + callerOffset: o.CallerOffset, } l.SetOutput(w) @@ -113,6 +114,11 @@ func SetCallerFormatter(f CallerFormatter) { defaultLogger.SetCallerFormatter(f) } +// SetCallerOffset sets the caller offset for the default logger. +func SetCallerOffset(offset int) { + defaultLogger.SetCallerOffset(offset) +} + // SetPrefix sets the prefix for the default logger. func SetPrefix(prefix string) { defaultLogger.SetPrefix(prefix)