Documentation
¶
Overview ¶
Package log provides a global logger for zerolog.
Index ¶
- Variables
- func Ctx(ctx context.Context) *zerolog.Logger
- func Debug() *zerolog.Event
- func Err(err error) *zerolog.Event
- func Error() *zerolog.Event
- func Errorf(format string, v ...interface{})
- func Fatal() *zerolog.Event
- func Info() *zerolog.Event
- func NewSplitWriter[f FormatInput, l LevelInput](userOut, devOut io.Writer, userFormat, devFormat f, userLevel, devLevel l) io.WriteCloser
- func Panic() *zerolog.Event
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Setup(ctx context.Context, opts ...SetupOption) context.Context
- func Trace() *zerolog.Event
- func Warn() *zerolog.Event
- type Config
- type Format
- type FormatInput
- type LevelInput
- type QlogAdapter
- type SetupOption
- func HostName(name string) SetupOption
- func PublicIP(ip string) SetupOption
- func Region(name string) SetupOption
- func ServiceName(name string) SetupOption
- func UpdateContext(f func(zerolog.Context) zerolog.Context) SetupOption
- func WithConfig(config Config) SetupOption
- func WithExtraWriters(w ...io.Writer) SetupOption
- func WithFormat[T FormatInput](format T) SetupOption
- func WithLevel[T LevelInput](level T) SetupOption
- func WithOutput(out io.Writer) SetupOption
Constants ¶
This section is empty.
Variables ¶
var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger()
Logger is the global logger.
Functions ¶
func Ctx ¶
Ctx returns the Logger associated with the ctx. If no logger is associated, a disabled logger is returned.
func Debug ¶
Debug starts a new message with debug level.
You must call Msg on the returned event in order to send the event.
func Err ¶
Err starts a new message with error level with err as a field if not nil or with info level if err is nil.
You must call Msg on the returned event in order to send the event.
func Error ¶
Error starts a new message with error level.
You must call Msg on the returned event in order to send the event.
func Errorf ¶ added in v0.1.2
func Errorf(format string, v ...interface{})
Errorf sends a log event using error level and no extra field. Arguments are handled in the manner of fmt.Printf.
func Fatal ¶
Fatal starts a new message with fatal level.
You must call Msg on the returned event in order to send the event.
func Info ¶
Info starts a new message with info level.
You must call Msg on the returned event in order to send the event.
func NewSplitWriter ¶
func NewSplitWriter[f FormatInput, l LevelInput](userOut, devOut io.Writer, userFormat, devFormat f, userLevel, devLevel l) io.WriteCloser
NewSplitWriter returns an output writer that logs to 2 targets with different output formats and levels. Use with WithFormat(FormatCustom). Using WithLevel would affect both outputs restricting them more. It doesn't overwrite the levels for the 2 outputs.
func Panic ¶
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 Print ¶
func Print(v ...interface{})
Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.
func Printf ¶
func Printf(format string, v ...interface{})
Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.
func Setup ¶
func Setup(ctx context.Context, opts ...SetupOption) context.Context
Setup is used to set up logging. If a context is passed, the logger will be added to the context and the context returned.
Types ¶
type Config ¶ added in v0.1.1
type Config struct {
LogLevel string `default:"debug" env:"LOG_LEVEL"`
LogFormat string `default:"color" env:"LOG_FORMAT"`
ServiceName string `env:"SERVICE_NAME"`
HostName string `env:"HOST_NAME"`
Region string `env:"REGION"`
PublicIP string `env:"PUBLIC_IP"`
HideCaller bool `env:"LOG_HIDE_CALLER"`
}
type Format ¶
type Format string
Format defines the log format.
const ( // FormatPlain uses a zerolog.ConsoleWriter without colors and sends the output to provided output or stdout. FormatPlain Format = "plain" // FormatPlainWithoutTime uses a zerolog.ConsoleWriter without colors and without time and sends the output to provided output or stdout. FormatPlainWithoutTime Format = "plain-notime" // FormatColor uses a zerolog.ConsoleWriter with colors and sends the output to provided output or stdout. FormatColor Format = "color" // FormatColorWithoutTime uses a zerolog.ConsoleWriter with colors and without time and sends the output to provided output or stdout. FormatColorWithoutTime Format = "color-notime" // FormatJSON writes JSON output to the output provided output or stdout. FormatJSON Format = "json" // FormatCustom can be used to pass in a custom output writer. FormatCustom Format = "custom" )
type FormatInput ¶
FormatInput allows the input format to be of type string or type Format.
type LevelInput ¶
LevelInput allows the level input to be of type string or type zerolog.Level.
type QlogAdapter ¶ added in v0.2.0
func NewQlogAdapter ¶ added in v0.2.0
func NewQlogAdapter(logger zerolog.Logger) *QlogAdapter
func (*QlogAdapter) Errorf ¶ added in v0.2.0
func (q *QlogAdapter) Errorf(format string, args ...any)
type SetupOption ¶
type SetupOption func(*setupOptions)
SetupOption defines an option for setting up the logging.
func ServiceName ¶
func ServiceName(name string) SetupOption
ServiceName sets the service name for logging.
func UpdateContext ¶
func UpdateContext(f func(zerolog.Context) zerolog.Context) SetupOption
UpdateContext can be used to update log context, adding additional information at setup.
func WithConfig ¶ added in v0.1.1
func WithConfig(config Config) SetupOption
func WithExtraWriters ¶ added in v0.1.10
func WithExtraWriters(w ...io.Writer) SetupOption
WithExtraWriters adds extra writers to the logger, so you can use any Format option.
func WithFormat ¶
func WithFormat[T FormatInput](format T) SetupOption
WithFormat sets the format to use for logging.
func WithLevel ¶
func WithLevel[T LevelInput](level T) SetupOption
WithLevel sets the global log level to use for logging.
func WithOutput ¶
func WithOutput(out io.Writer) SetupOption
WithOutput sets the writer to write the log output to. Can be used to use a customized output writer. Doing so should be done in combination with passing FormatCustom to WithFormat.