https://github.com/powerman/structlog
Structured logger for Go
https://github.com/powerman/structlog
Last synced: 3 months ago
JSON representation
Structured logger for Go
- Host: GitHub
- URL: https://github.com/powerman/structlog
- Owner: powerman
- License: mit
- Created: 2016-11-13T22:33:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-25T21:21:20.000Z (about 1 year ago)
- Last Synced: 2025-05-06T03:58:07.505Z (8 months ago)
- Language: Go
- Homepage:
- Size: 2.42 MB
- Stars: 19
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# structlog
[](https://pkg.go.dev/github.com/powerman/structlog)
[](https://github.com/powerman/structlog/actions?query=workflow%3ACI%2FCD)
[](https://coveralls.io/github/powerman/structlog?branch=master)
[](https://goreportcard.com/report/github.com/powerman/structlog)
[](https://github.com/powerman/structlog/releases/latest)
## 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
- 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