Fix: Implement Output method from stdlib

This commit is contained in:
kayos@tcp.direct 2023-08-04 23:23:37 -07:00
parent 2817693224
commit 1f997319a3
Signed by: kayos
GPG Key ID: 4B841471B4BEE979

17
wrap.go

@ -30,6 +30,7 @@ type StdCompatLogger interface {
Printf(format string, v ...interface{})
Println(v ...interface{})
SetPrefix(prefix string)
Output(calldepth int, s string) error
}
// assert that Logger implements StdCompatLogger and that log.Logger implements StdCompatLogger
@ -182,6 +183,22 @@ func (l *Logger) Traceln(v ...interface{}) {
l.RUnlock()
}
func (l *Logger) Output(calldepth int, s string) error {
l.RLock()
event := l.Logger.Info()
if calldepth != 2 {
if l.prefix != "" {
zerolog.CallerFieldName = "caller_file"
}
event.CallerSkipFrame(calldepth)
event = event.Caller()
}
event.Msg(s)
zerolog.CallerFieldName = "caller"
l.RUnlock()
return nil
}
func printLn(e *zerolog.Event, v ...interface{}) {
strBuf := strBufs.Get().(*strings.Builder)
for i, v := range v {