Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Outputs used for the stdout and stderr writer types.
Functions ¶
func MinMaxLevelWriter ¶
MinMaxLevelWriter wraps a writer in a zerolog.LevelWriter, but limits the log levels that can pass through.
func RegisterWriter ¶ added in v0.1.2
func RegisterWriter(wt WriterType, compiler WriterCompiler)
Types ¶
type Config ¶
type Config struct { Writers []WriterConfig `json:"writers,omitempty" yaml:"writers,omitempty"` MinLevel *zerolog.Level `json:"min_level,omitempty" yaml:"min_level,omitempty"` Timestamp *bool `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` Caller bool `json:"caller,omitempty" yaml:"caller,omitempty"` Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty"` }
Config contains all the configuration to create a zerolog logger.
type FileConfig ¶
type FileConfig struct { // File name for the current log. Backups will be stored in the same directory, named as name-<timestamp>.ext Filename string `json:"filename,omitempty" yaml:"filename,omitempty"` // Maximum size in megabytes for the log file before rotating. Defaults to 100 megabytes. MaxSize int `json:"max_size,omitempty" yaml:"max_size,omitempty"` // Maximum age of rotated log files to keep as days. Defaults to no limit. MaxAge int `json:"max_age,omitempty" yaml:"max_age,omitempty"` // Maximum number of rotated log files to keep. Defaults to no limit. MaxBackups int `json:"max_backups,omitempty" yaml:"max_backups,omitempty"` // Should rotated log file names use local time instead of UTC? Defaults to false. LocalTime bool `json:"local_time,omitempty" yaml:"local_time,omitempty"` // Should rotated log files be compressed with gzip? Defaults to false. Compress bool `json:"compress,omitempty" yaml:"compress,omitempty"` }
FileConfig contains the configuration options for the file writer.
See https://github.com/natefinch/lumberjack for exact details.
type LogFormat ¶
type LogFormat string
LogFormat describes how logs should be formatted for a writer.
const ( // LogFormatJSON outputs logs as the raw JSON that zerolog produces. LogFormatJSON LogFormat = "json" // LogFormatPretty uses zerolog's console writer, but disables color. LogFormatPretty LogFormat = "pretty" // LogFormatPrettyColored uses zerolog's console writer including color. LogFormatPrettyColored LogFormat = "pretty-colored" )
type SyslogConfig ¶
type SyslogConfig struct { // All parameters are passed to https://pkg.go.dev/log/syslog#Dial directly. Network string `json:"network,omitempty" yaml:"network,omitempty"` Host string `json:"host,omitempty" yaml:"host,omitempty"` Flags int `json:"flags,omitempty" yaml:"flags,omitempty"` Tag string `json:"tag,omitempty" yaml:"tag,omitempty"` }
SyslogConfig contains the configuration options for the syslog writer.
See https://pkg.go.dev/log/syslog for exact details.
type WriterCompiler ¶ added in v0.1.2
type WriterCompiler = func(*WriterConfig) (io.Writer, error)
type WriterConfig ¶
type WriterConfig struct { // The type of writer. Type WriterType `json:"type" yaml:"type"` Format LogFormat `json:"format,omitempty" yaml:"format,omitempty"` MinLevel *zerolog.Level `json:"min_level,omitempty" yaml:"min_level,omitempty"` MaxLevel *zerolog.Level `json:"max_level,omitempty" yaml:"max_level,omitempty"` // Only applies when format=console or format=console-colored TimeFormat string `json:"time_format,omitempty" yaml:"time_format,omitempty"` SyslogConfig `json:",inline,omitempty" yaml:",inline,omitempty"` FileConfig `json:",inline,omitempty" yaml:",inline,omitempty"` }
WriterConfig contains the configuration for an individual log writer.
type WriterType ¶
type WriterType string
WriterType is a type of writer.
const ( // WriterTypeStdout writes to stdout. WriterTypeStdout WriterType = "stdout" // WriterTypeStderr writes to stderr. WriterTypeStderr WriterType = "stderr" // WriterTypeFile writes to a file, including rotating the file when it gets big. // The configuration is stored in the FileConfig struct. WriterTypeFile WriterType = "file" // WriterTypeSyslog writes to the system logging service. // The configuration is stored in the SyslogConfig struct. WriterTypeSyslog WriterType = "syslog" // WriterTypeSyslogCEE writes to the system logging service with MITRE CEE prefixes. WriterTypeSyslogCEE WriterType = "syslog-cee" // WriterTypeJournald writes to systemd's logging service. WriterTypeJournald WriterType = "journald" )
Click to show internal directories.
Click to hide internal directories.