Documentation
¶
Overview ¶
Package log provides a common way to quickly configure a logging implementation with file rotation, syslog, console output, etc. for some popular logging implementations such as zerolog.
This package defines the configuration interface, which is json-encodable.
Loggers are concretely implemented by the packages in the subfolder e.g. tawesoft.co.uk/go/log/zerolog.
The package also wraps the stdlib syslog as an interface without it being a compile-time constraint so that it can be imported on platforms that don't support syslog (like Windows), giving a runtime error if used instead.
Package Information ¶
License: MIT-0 (see LICENSE.txt)
Stable: candidate
For more information, documentation, source code, examples, support, links, etc. please see https://www.tawesoft.co.uk/go and https://www.tawesoft.co.uk/go/log
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Syslog ConfigSyslog File ConfigFile Stderr ConfigStderr }
type ConfigFile ¶
type ConfigFile struct { Enabled bool // Mode to use when creating the file e.g. 0644, 0600 Mode os.FileMode // Path to write the current (non-rotated) file. Rotated files appear // in the same directory. Path string // If Rotate is true, logs are rotated (e.g. like logrotate) once they // get to a certain size. Rotate bool // If RotateCompress is true, rotated log files are compressed (read them // with zless, zcat, or gunzip, for example) RotateCompress bool // A log is rotated if it would be bigger than RotateMaxSize (in bytes) RotateMaxSize int // bytes // If non-zero, delete any rotated logs older than RotateKeepAge RotateKeepAge time.Duration // If non-zero, keep only this many rotated logs and delete any exceeding // the limit of RotateKeepNumber. RotateKeepNumber int }
ConfigFile configures a file logger, with optional file rotation
func (ConfigFile) MarshalJSON ¶ added in v0.8.0
func (c ConfigFile) MarshalJSON() ([]byte, error)
func (*ConfigFile) UnmarshalJSON ¶ added in v0.8.0
func (c *ConfigFile) UnmarshalJSON(data []byte) error
type ConfigStderr ¶
type ConfigStderr struct { Enabled bool // If Color is true, output is colourised iff Stderr is attached to // a terminal. Color bool }
ConfigStdio configures a logger which writes to Stderr
func (ConfigStderr) ShouldColorize ¶ added in v0.6.0
func (c ConfigStderr) ShouldColorize(output *os.File) bool
ShouldColorize returns true if the output should be colourised (if possible) for a given output (e.g. os.Stderr). This is true when both the config Color field is true and the output is a terminal.
type ConfigSyslog ¶
type ConfigSyslog struct { Enabled bool Network string // See syslog.Dial Address string // See syslog.Dial Priority Priority // See syslog.Dial Tag string // See syslog.Dial }
ConfigSyslog configures a syslog logger
func (ConfigSyslog) Dial ¶
func (c ConfigSyslog) Dial() (Syslog, error)
Dial connects to a local or remote syslog.
func (ConfigSyslog) MarshalJSON ¶ added in v0.8.0
func (c ConfigSyslog) MarshalJSON() ([]byte, error)
func (*ConfigSyslog) UnmarshalJSON ¶ added in v0.8.0
func (c *ConfigSyslog) UnmarshalJSON(data []byte) error
type Priority ¶
type Priority int
Priority is a combination of the syslog facility and severity. See https://pkg.go.dev/log/syslog#Priority
func ParsePriority ¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
Package log/zero makes it trivial to configure a zerolog logger with syslog, rotating file, and/or console output using the same uniform configuration interface.
|
Package log/zero makes it trivial to configure a zerolog logger with syslog, rotating file, and/or console output using the same uniform configuration interface. |