Documentation
¶
Overview ¶
Package zerolog_wrapper provides a custom log wrapper based on github.com/rs/zerolog
How to use:
import (
log "github.com/ashokrajar/zerolog_wrapper"
)
func init() {
log.InitLog(log.TraceLevel, "dev")
}
func main() {
log.Info().Msg("hello world")
}
// Output: {"time":1494567715,"level":"info","message":"hello world"}
Fields can be added to log messages:
log.Info().Str("foo", "bar").Msg("hello world")
// Output: {"time":1494567715,"level":"info","message":"hello world","foo":"bar"}
Updating the logger context ¶
log.UpdateContext(func(c zerolog.Context) zerolog.Context {
return c.Str("some_default_key", "some_default_value")
})
Index ¶
- func Debug() *zerolog.Event
- func Error() *zerolog.Event
- func Fatal() *zerolog.Event
- func GetLogger() zerolog.Logger
- func Info() *zerolog.Event
- func InitLog(logLevelStr LogLevel, appEnv Env)
- func Panic() *zerolog.Event
- func Trace() *zerolog.Event
- func UpdateContext(update func(c zerolog.Context) zerolog.Context)
- func Warn() *zerolog.Event
- type Env
- type LogLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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.
You must call Msg on the returned event in order to send the event.
func GetLogger ¶ added in v0.4.0
GetLogger returns the global logger from the zerolog package.
Returns:
The zerolog.Logger instance used for logging in the application.
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 Panic ¶
Panic starts a new message with panic level.
You must call Msg on the returned event in order to send the event.
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 v0.2.0
UpdateContext is a function that updates the internal logger's context.
Parameters: update: A function taking a zerolog.Context as input and then returns a zerolog.Context.
eg:
log.UpdateContext(func(c zerolog.Context) zerolog.Context {
return c.Str("some_default_key", "some_default_value")
})