Documentation ¶
Index ¶
- Constants
- func CreateLogger(id string, lvl zerolog.Level, withTimestamp bool, withCaller bool, ...)
- func DefaultGlobalFieldNames() map[GlobalField]string
- func GetLogger(id string) *zerolog.Logger
- func SetupDefaults(lvl zerolog.Level, withTimestamp bool, withCaller bool, ...)
- func SetupGlobalConf(conf *GlobalConf)
- type GlobalConf
- func (conf *GlobalConf) SetCallerSkipFrameCount(n int) *GlobalConf
- func (conf *GlobalConf) SetFieldNames(names map[GlobalField]string) *GlobalConf
- func (conf *GlobalConf) SetLevel(lvl zerolog.Level) *GlobalConf
- func (conf *GlobalConf) SetTimestampFormat(fmt string) *GlobalConf
- func (conf *GlobalConf) SetTimestampFunc(f func() time.Time) *GlobalConf
- type GlobalField
Constants ¶
const ( TimestampField GlobalField = "field-timestamp" LevelField = "field-level" MessageField = "field-message" ErrorField = "field-error" CallerField = "field-caller" )
Global Fields
Variables ¶
This section is empty.
Functions ¶
func CreateLogger ¶
func CreateLogger( id string, lvl zerolog.Level, withTimestamp bool, withCaller bool, wcreator writer.LogWriterCreator)
CreateLogger creates a logger and stores it for later retrieving. This SHOULD be called at app startup to setup loggers.
func DefaultGlobalFieldNames ¶
func DefaultGlobalFieldNames() map[GlobalField]string
DefaultGlobalFieldNames returns a map containing defaults names for global fields:
timestamp: "log-ts" level: "log-level" message: "message" error: "error" caller: "caller"
func GetLogger ¶
GetLogger retrieves an existing logger or creates a new one with logger default settings.
func SetupDefaults ¶
func SetupDefaults( lvl zerolog.Level, withTimestamp bool, withCaller bool, writerCreator writer.LogWriterCreator)
SetupDefaults sets up default settings for logger. Inside GetLogger(), it creates logger from this defaults if the requested logger doesn't exist.
func SetupGlobalConf ¶
func SetupGlobalConf(conf *GlobalConf)
SetupGlobalConf sets the global configurations of zerolog, it can be called multiple times and the last call wins but it MUST be called before GetLogger() is called.
Types ¶
type GlobalConf ¶
type GlobalConf struct {
// contains filtered or unexported fields
}
GlobalConf contains global configurations for zerolog which can only be changed before any zerolog instance is created.
func DefaultGlobalConf ¶
func DefaultGlobalConf() *GlobalConf
DefaultGlobalConf returns a GlobalConf instance with default values.
func (*GlobalConf) SetCallerSkipFrameCount ¶
func (conf *GlobalConf) SetCallerSkipFrameCount(n int) *GlobalConf
SetCallerSkipFrameCount sets the skip count when getting caller info. Default value is 2.
func (*GlobalConf) SetFieldNames ¶
func (conf *GlobalConf) SetFieldNames(names map[GlobalField]string) *GlobalConf
SetFieldNames change the name(s) of globl fields.
func (*GlobalConf) SetLevel ¶
func (conf *GlobalConf) SetLevel(lvl zerolog.Level) *GlobalConf
SetLevel sets the global log level for zerolog.
func (*GlobalConf) SetTimestampFormat ¶
func (conf *GlobalConf) SetTimestampFormat(fmt string) *GlobalConf
SetTimestampFormat sets the format string for the timestamp field value. The default format is empty string ("") which causes a unix time (seconds elapsed since January 1, 1970 UTC) is logged.
func (*GlobalConf) SetTimestampFunc ¶
func (conf *GlobalConf) SetTimestampFunc(f func() time.Time) *GlobalConf
SetTimestampFunc sets the function which generates the value for the timestamp field. Default function returns time.Now().UTC().