Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallerHook ¶
type CallerHook struct {
WithFunc bool // Include function name
WithFile bool // Include filename
WithLine bool // Include line number
WithPkg bool // Include package name
}
CallerHook is a Zerolog hook that automatically adds caller information (function name, package name, filename, and line number) to the log entry. Each field can be configured individually at the time of creation.
func NewCallerHook ¶
func NewCallerHook(withFunc, withFile, withLine, withPkg bool) CallerHook
NewCallerHook creates a new instance of CallerHook
- withFunc: whether to include the function name
- withFile: whether to include the filename
- withLine: whether to include the line number
- withPkg: whether to include the package name
example:
logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
logger = logger.Hook(NewCallerHook(true, true, true, true))
logger.Info().Msg("test log")
// Output: {"level":"info","time":...,"func":"captureLog","file":"caller_hook_test.go","line":...,"pkg":"loggerhook_test","message":"test log"}
Click to show internal directories.
Click to hide internal directories.