github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/logging/logger.go (about)

     1  package logging
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/rs/zerolog"
     8  )
     9  
    10  var Logger zerolog.Logger
    11  
    12  func init() {
    13  	SetGlobalLogger(zerolog.Nop())
    14  }
    15  
    16  func SetGlobalLogger(logger zerolog.Logger) {
    17  	Logger = logger
    18  	zerolog.DefaultContextLogger = &Logger
    19  }
    20  
    21  func With() zerolog.Context { return Logger.With() }
    22  
    23  func Err(err error) *zerolog.Event { return Logger.Err(err) }
    24  
    25  func Trace() *zerolog.Event { return Logger.Trace() }
    26  
    27  func Debug() *zerolog.Event { return Logger.Debug() }
    28  
    29  func Info() *zerolog.Event { return Logger.Info() }
    30  
    31  func Warn() *zerolog.Event { return Logger.Warn() }
    32  
    33  func Error() *zerolog.Event { return Logger.Error() }
    34  
    35  func Fatal() *zerolog.Event { return Logger.Fatal() }
    36  
    37  func WithLevel(level zerolog.Level) *zerolog.Event { return Logger.WithLevel(level) }
    38  
    39  func Log() *zerolog.Event { return Logger.Log() }
    40  
    41  func Ctx(ctx context.Context) *zerolog.Logger { return zerolog.Ctx(ctx) }
    42  
    43  func Print(v ...interface{}) {
    44  	Logger.Debug().CallerSkipFrame(1).Msg(fmt.Sprint(v...))
    45  }
    46  
    47  func Printf(format string, v ...interface{}) {
    48  	Logger.Debug().CallerSkipFrame(1).Msgf(format, v...)
    49  }