Documentation
¶
Index ¶
- func InitFromConfig(cfgPath string) error
- func SetGlobalLabels(labels []Label)
- type ConfigModel
- type HandlerConfigModel
- type Label
- type LabelType
- type LogEvent
- func (le LogEvent) Debug(message string, messageParams ...any)
- func (le LogEvent) Error(message string, messageParams ...any)
- func (le LogEvent) Info(message string, messageParams ...any)
- func (le LogEvent) Warn(message string, messageParams ...any)
- func (le LogEvent) WithLabel(label Label) LogEvent
- func (le LogEvent) WithLabels(labels []Label) LogEvent
- type LogLevel
- type Logger
- func (l Logger) Debug(message string, messageParams ...any)
- func (l Logger) Error(message string, messageParams ...any)
- func (l Logger) GetHandlers() map[string]*zap.Logger
- func (l Logger) GetLevel() LogLevel
- func (l Logger) GetName() string
- func (l Logger) Info(message string, messageParams ...any)
- func (l *Logger) Log(level LogLevel, message string, messageParams ...any)
- func (l Logger) Warn(message string, messageParams ...any)
- func (l *Logger) WithLabel(label Label) LogEvent
- func (l *Logger) WithLabels(labels []Label) LogEvent
- type LoggerConfigModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitFromConfig ¶
Initializing the logging from the .yaml or .json config file available on the given path
func SetGlobalLabels ¶
func SetGlobalLabels(labels []Label)
you can change the GlobalLabels with this - the key-value pairs attached to all log events
Types ¶
type ConfigModel ¶
type ConfigModel struct { Loggers map[string]LoggerConfigModel `json:"loggers" yaml:"loggers"` Handlers map[string]HandlerConfigModel `json:"handlers" yaml:"handlers"` }
for json/yaml config file parsing - this is root level object
type HandlerConfigModel ¶
type HandlerConfigModel struct { Level string `json:"level" yaml:"level"` Encoding string `json:"encoding" yaml:"encoding"` OutputPaths []string `json:"outputPaths" yaml:"outputPaths"` }
for json/yaml config file parsing - this is the entries in /handlers path
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
A Label can carry a certain key-value pair. Regarding the value the atomic JSON data types are supported: string, bool, numeric values. Complex structures like array/object are not as we do not want to bring this complexity as a key-value into central persistence layers (like Elastic Search or similar). You can marshal complex structures into a JSON string before logging and just log the string representation
func FloatLabel ¶
constructs a Float label with the given key and value.
func GetGlobalLabels ¶
func GetGlobalLabels() []Label
returns the current GlobalLabels - key-value pairs attached to all log events
func StringLabel ¶
constructs a String label with the given key and value.
type LabelType ¶
type LabelType uint8
A LabelType indicates the data type the Label carries
const ( // UnknownType is the default Label type. Attempting to add it to an encoder will panic. UnknownType LabelType = iota // BoolType indicates that the Label carries a bool. BoolType // FloatType indicates that the Label carries a float64. FloatType // IntType indicates that the Label carries an int64. IntType // StringType indicates that the Label carries a string. StringType )
type LogEvent ¶
type LogEvent struct {
// contains filtered or unexported fields
}
func (LogEvent) WithLabels ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func GetLogger ¶
returns a Logger with the given name - if does not exist then a new instance is created with this name and registered note: Loggers are hierarchical
func (Logger) GetHandlers ¶
returns the attached Handlers
func (*Logger) Log ¶
logs the given message resolved with (optional) messageParams (Printf() style) on the given log level in case the the message is filtered out due to configured log level then the message string is not built at all
func (*Logger) WithLabel ¶
Decorates the upcoming LogEvent (when you invoke .info(), .error() etc method the LogEvent is fired) with the given label. If you have multiple labels to add consider using .WithLabels() method instead. Please note: the label will be just used in the upcoming LogEvent and after that forgotten!
func (*Logger) WithLabels ¶
Decorates the upcoming LogEvent (when you invoke .info(), .error() etc method the LogEvent is fired) with the given labels. Please note: the labels will be just used in the upcoming LogEvent and after that forgotten!
type LoggerConfigModel ¶
type LoggerConfigModel struct { Name string `json:"name" yaml:"name"` Level string `json:"level" yaml:"level"` HandlerNames []string `json:"handlers" yaml:"handlers"` }
for json/yaml config file parsing - this is the entries in /loggers path