Documentation ¶
Index ¶
- Constants
- Variables
- func Ctx(ctx context.Context) *zerolog.Logger
- func Debug() *zerolog.Event
- func Err(err error) *zerolog.Event
- func Error() *zerolog.Event
- func Fatal() *zerolog.Event
- func GetLevel() zerolog.Level
- func GlobalLevel() zerolog.Level
- func Hook(h zerolog.Hook) zerolog.Logger
- func Info() *zerolog.Event
- func Level(level zerolog.Level) zerolog.Logger
- func Log() *zerolog.Event
- func MultiLevelWriter(writers ...io.Writer) io.Writer
- func Output(w io.Writer) zerolog.Logger
- func Panic() *zerolog.Event
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Sample(s zerolog.Sampler) zerolog.Logger
- func SetGlobalLevel(l zerolog.Level)
- func Trace() *zerolog.Event
- func UpdateContext(update func(c zerolog.Context) zerolog.Context)
- func Warn() *zerolog.Event
- func With() zerolog.Context
- func WithConsoleWriter() io.Writer
- func WithContext(ctx context.Context) context.Context
- func WithFileWriter(path string) io.Writer
- func WithLevel(level zerolog.Level) *zerolog.Event
- func WithOptions(opts ...Option)
- type Option
- type SentryHook
Constants ¶
const DebugLevel = zerolog.DebugLevel
const DefaultLevel = zerolog.WarnLevel
const FileNameTimeFormat = "2006-01-02_15_04_05.log"
Variables ¶
var CallerMarshalFunc = func(_ uintptr, file string, line int) string { file = file[countParentDirectories(file, MaxPathNumber):] return file + ":" + strconv.Itoa(line) }
var MaxPathNumber = 0
Functions ¶
func Ctx ¶ added in v0.2.0
Ctx returns the zerolog.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 ¶ added in v0.2.0
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 Fatal ¶
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 GetLevel ¶ added in v1.5.0
GetLevel is a function that returns the current logging level of the logger. The logging level is of type zerolog.Level, which is an integer type where higher values represent lower severity levels.
This function is useful when you want to check the current logging level programmatically, for example to only execute certain code if the logging level is set to a certain severity.
func GlobalLevel ¶ added in v1.5.2
GlobalLevel is a function that returns the current global logging level. The logging level is of type zerolog.Level, which is an integer type where higher values represent lower severity levels.
This function is useful when you want to check the current global logging level programmatically, for example to only execute certain code if the global logging level is set to a certain severity.
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 Level ¶ added in v0.2.0
Level creates a child logger with the minimum accepted level set to level.
func Log ¶
Log starts a new message with no level. Setting zerolog.GlobalLevel to zerolog.Disabled will still disable events produced by this method.
You must call Msg on the returned event in order to send the event.
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 SetGlobalLevel ¶ added in v1.5.2
SetGlobalLevel is a function that sets the global logging level. The logging level is of type zerolog.Level, which is an integer type where higher values represent lower severity levels. The levels are as follows: 0=panic, 1=fatal, 2=error, 3=warn, 4=info, 5=debug, 6=trace.
This function is useful when you want to set the global logging level programmatically, for example to control the overall verbosity of your application.
Parameters:
l (zerolog.Level): The logging level to set as the global level.
func Trace ¶
Trace starts a new message with trace level.
You must call Msg on the returned event in order to send the event.
func UpdateContext ¶ added in v1.3.0
UpdateContext updates the internal logger's context.
Caution: This method is not concurrency safe. Use the With method to create a child logger before modifying the context from concurrent goroutines.
func Warn ¶
Warn starts a new message with warn level.
You must call Msg on the returned event in order to send the event.
func WithConsoleWriter ¶ added in v0.2.0
func WithContext ¶ added in v1.3.0
WithContext returns a copy of ctx with the receiver attached. The Logger attached to the provided Context (if any) will not be effected. If the receiver's log level is Disabled it will only be attached to the returned Context if the provided Context has a previously attached Logger. If the provided Context has no attached Logger, a Disabled Logger will not be attached.
func WithFileWriter ¶ added in v0.2.0
func WithLevel ¶
WithLevel starts a new message with level.
You must call Msg on the returned event in order to send the event.
func WithOptions ¶ added in v0.2.0
func WithOptions(opts ...Option)
Types ¶
type Option ¶ added in v0.2.0
Option is a function that takes a pointer to a Logger and sets its options. This is used to apply different configurations to the logger.
func WithMaxPathParents ¶ added in v1.5.2
WithMaxPathParents is a function that takes an integer value and returns an Option. This option sets the maximum number of parent directories that will be included in the log's path.
This function is useful when you want to limit the verbosity of the file paths in your logs. For example, if you set max to 2, only the last two directories in the path will be included.
func WithSentry ¶ added in v0.2.0
func WithSentry() Option
WithSentry is a function that returns an option. This option adds a Sentry hook to the logger. The Sentry hook is used to send logs to a Sentry server for error tracking and monitoring.
func WithVerbosity ¶ added in v0.2.0
WithVerbosity is a function that takes an integer value and returns an option. This option sets the logger's level based on the provided verbosity. The verbosity is subtracted from the Panic level to determine the log level.
func WithWriter ¶ added in v1.1.0
WithWriter is a function that takes an io.Writer and returns an option. This option sets the logger's output destination to the provided io.Writer. This is similar to WithOutput, but can be used when you want to specify a different writer.
type SentryHook ¶ added in v0.2.0
type SentryHook struct{}