85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
// Package log provides a global logger for zerolog.
|
|
package log
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
// Logger is the global logger.
|
|
var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger()
|
|
|
|
// With creates a child logger with the field added to its context.
|
|
func With() zerolog.Context {
|
|
return Logger.With()
|
|
}
|
|
|
|
// Level crestes a child logger with the minium accepted level set to level.
|
|
func Level(level zerolog.Level) zerolog.Logger {
|
|
return Logger.Level(level)
|
|
}
|
|
|
|
// Sample returns a logger that only let one message out of every to pass thru.
|
|
func Sample(every int) zerolog.Logger {
|
|
return Logger.Sample(every)
|
|
}
|
|
|
|
// Debug starts a new message with debug level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Debug() *zerolog.Event {
|
|
return Logger.Debug()
|
|
}
|
|
|
|
// Info starts a new message with info level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Info() *zerolog.Event {
|
|
return Logger.Info()
|
|
}
|
|
|
|
// Warn starts a new message with warn level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Warn() *zerolog.Event {
|
|
return Logger.Warn()
|
|
}
|
|
|
|
// Error starts a new message with error level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Error() *zerolog.Event {
|
|
return Logger.Error()
|
|
}
|
|
|
|
// Fatal starts a new message with fatal level. The os.Exit(1) function
|
|
// is called by the Msg method.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Fatal() *zerolog.Event {
|
|
return Logger.Fatal()
|
|
}
|
|
|
|
// Panic starts a new message with panic level. The message is also sent
|
|
// to the panic function.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Panic() *zerolog.Event {
|
|
return Logger.Panic()
|
|
}
|
|
|
|
// Log starts a new message with no level. Setting zerolog.GlobalLevel to
|
|
// zerlog.Disabled will still disable events produced by this method.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Log() *zerolog.Event {
|
|
return Logger.Log()
|
|
}
|
|
|
|
// Ctx returns the Logger associated with the ctx. If no logger
|
|
// is associated, a disabled logger is returned.
|
|
func Ctx(ctx context.Context) zerolog.Logger {
|
|
return zerolog.Ctx(ctx)
|
|
}
|