logging

package module
v0.0.0-...-d7aea0d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
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

func GetLogger(id string) *zerolog.Logger

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().

type GlobalField

type GlobalField string

GlobalField is the type for global field

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL