# README
structlog
Features
- log only key/value pairs
- output both as Text and JSON
- log level support
- compatible enough with log.Logger to use as drop-in replacement
- short names for service keys (like log level, time, etc.)
- support default values for keys
- service keys with caller's function name, file and line
- fixed log level width
- service key for high-level source name (like package or subsystem), caller's package name by default
- when creating new logger instance:
- inherit default logger settings (configured in main())
- add new default key/values
- disable inherited default keys
- warn about imbalanced key/value pairs
- first parameter to log functions should be value for "message" service key
- able to output stack trace
- level-guards like IsDebug()
- output complex struct as key values (using "%v" like formatting)
- Error returns message as error (auto-convert from string, if needed)
- actually it returns first
.(error)
arg if any or message otherwise
- actually it returns first
- convenient helpers IfFail and Recover for use with defer
- output can be redirected/intercepted
- when output as JSON:
- add service field time by default
- when output as Text:
- do not add service field time by default
- order of keys in output is fixed, same as order of log function parameters
- it is possible to set minimal width for some keys (both user and service ones)
- it is possible to setup order for service keys, including this keys should be output before and after user keys
- it is possible to choose output style for some keys: "key: ", "key=", do not output key name
- it is possible to choose how to escape values by default and for selected keys: no escaping, use ``, use ""
- do not support colored output - this can be added by external tools like grc and we anyway won't have colors in log files
# Functions
FromContext returns the Logger value stored in ctx or defaultLog or New() if defaultLog is nil.
New creates and returns a new logger which inherits all settings from DefaultLogger.
NewContext returns a new Context that carries value log.
NewZeroLogger creates and returns a new logger with empty settings.
ParseLevel convert levelName from flag or config file into logLevel.
# Constants
Auto can be used as value for KeyTime, KeyUnit and KeyStack to automatically generate their values: current time, caller package's directory name and full stack of the current goroutine.
Log levels.
Defaults.
Defaults.
Defaults.
Defaults.
Defaults.
Log levels.
Log levels.
Log formats.
Key name used to output app name.
Key name used to output caller's function name.
Key name used to output log level.
Key name used to output log message.
Key name used to output PID.
Key name used to output caller's file and line.
Key name used to output multiline stack trace.
Key name used to output current time.
Key name used to output unit/module/package name.
Defaults.
Log formats.
Log levels.
# Variables
DefaultLogger provides sane defaults inherited by new logger objects created with New().
# Interfaces
Printer is an interface used to output log.
# Type aliases
The PrinterFunc type is an adapter to allow the use of ordinary functions as Printer.