Documentation ¶
Overview ¶
Package zerolog provides opinionated configuration of the zerolog package.
For details on what all is configured and initialized see package's README.
Index ¶
- Constants
- Variables
- func New[LoggingConfigT hasLoggingConfig](config LoggingConfigT) (*os.File, errors.E)
- func NewHandler(withContext func(context.Context) (context.Context, func(), func())) func(http.Handler) http.Handler
- func PrettyLog(noColor bool, input io.Reader, output io.Writer) errors.E
- type Console
- type Context
- type File
- type Logging
- type LoggingConfig
- type Main
Constants ¶
const ( DefaultConsoleType = "color" DefaultConsoleLevel = "debug" DefaultFileLevel = "debug" DefaultMainLevel = "info" DefaultContextLevel = "debug" DefaultContextConditionalLevel = "debug" DefaultContextTriggerLevel = "error" )
Defaults to be used with Kong initialization for LoggingConfig struct:
kong.Vars{ "defaultLoggingConsoleType": DefaultConsoleType, "defaultLoggingConsoleLevel": DefaultConsoleLevel, "defaultLoggingFileLevel": DefaultFileLevel, "defaultLoggingMainLevel": DefaultMainLevel, "defaultLoggingContextLevel": DefaultContextLevel, "defaultLoggingContextConditionalLevel": DefaultContextConditionalLevel, "defaultLoggingContextTriggerLevel": DefaultContextTriggerLevel, }
const TimeFieldFormat = "2006-01-02T15:04:05.000Z07:00"
TimeFieldFormat is the format for timestamps in log entries.
Variables ¶
var KongLevelTypeMapper = kongLevelTypeMapper
KongLevelTypeMapper should be used with Kong initialization so that logging levels found in LoggingConfig struct can be correctly parsed on populated.
Functions ¶
func New ¶
New configures and initializes zerolog and Go's standard log package for logging.
New expects configuration embedded inside config as a LoggingConfig struct and returns the logger in its Logger field and sets its WithContext field. LoggingConfig can be initially populated with configuration using Kong.
Returned file handle belongs to the file to which log entries are appended (if file logging is enabled in configuration). Closing it is caller's responsibility.
For details on what all is configured and initialized see package's README.
Types ¶
type Console ¶
type Console struct { Type string `` /* 229-byte string literal not displayed */ Level zerolog.Level `` /* 230-byte string literal not displayed */ // Used primarily for testing. Output io.Writer `json:"-" kong:"-" yaml:"-"` }
Console is configuration of logging log entries to the console (stdout by default).
Type can be the following values: color (human-friendly formatted and colorized), nocolor (just human-friendly formatted), json, disable (do not log to the console).
Level can be trace, debug, info, warn, and error.
func (*Console) UnmarshalJSON ¶
func (*Console) UnmarshalYAML ¶
type Context ¶
type Context struct { Level zerolog.Level `` /* 306-byte string literal not displayed */ ConditionalLevel zerolog.Level `` /* 317-byte string literal not displayed */ TriggerLevel zerolog.Level `` /* 313-byte string literal not displayed */ }
Context is configuration of the context logger.
Levels can be trace, debug, info, warn, and error. Level can be also disabled to disable context logger.
It supports buffering log lines at the ConditionalLevel or below until triggered by a log entry at the TriggerLevel or higher. To disable this behavior, set Level and TriggerLevel to the same level.
func (*Context) UnmarshalJSON ¶
func (*Context) UnmarshalYAML ¶
type File ¶
type File struct { Path string `` /* 235-byte string literal not displayed */ Level zerolog.Level `` /* 236-byte string literal not displayed */ }
File is configuration of logging log entries as JSON by appending them to a file at path.
Level can be trace, debug, info, warn, and error.
func (*File) UnmarshalJSON ¶
func (*File) UnmarshalYAML ¶
type Logging ¶
type Logging struct { Console Console `embed:"" json:"console" prefix:"console." yaml:"console"` File File `embed:"" json:"file" prefix:"file." yaml:"file"` Main Main `embed:"" json:"main" prefix:"main." yaml:"main"` Context Context `embed:"" json:"context" prefix:"context." yaml:"context"` }
Logging is configuration for console and file logging.
type LoggingConfig ¶
type LoggingConfig struct { Logger zerolog.Logger ` json:"-" kong:"-" yaml:"-"` WithContext func(context.Context) (context.Context, func(), func()) ` json:"-" kong:"-" yaml:"-"` Logging Logging `embed:"" json:"logging" prefix:"logging." yaml:"logging"` }
LoggingConfig struct can be provided embedded inside the config argument to function New and function New returns the logger in its Logger field and sets its WithContext field.
func (*LoggingConfig) GetLoggingConfig ¶ added in v0.4.0
func (l *LoggingConfig) GetLoggingConfig() *LoggingConfig
type Main ¶
Main is configuration of the main logger.
Level can be trace, debug, info, warn, and error. Level can be also disabled to disable main logger.