Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/omrilotan/jonson
Out-of-the-box JSON logger
https://github.com/omrilotan/jonson
json logger structured-logging
Last synced: 3 months ago
JSON representation
Out-of-the-box JSON logger
- Host: GitHub
- URL: https://github.com/omrilotan/jonson
- Owner: omrilotan
- License: unlicense
- Created: 2024-07-03T09:47:22.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-07-09T15:04:08.000Z (6 months ago)
- Last Synced: 2024-10-12T19:07:25.582Z (3 months ago)
- Topics: json, logger, structured-logging
- Language: Python
- Homepage: https://pypi.org/project/jonson/
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jonson [![](https://img.shields.io/pypi/v/jonson?style=flat-square)](https://pypi.org/project/jonson/) [![](https://img.shields.io/static/v1?label=github&message=jonson&labelColor=black&color=3572a5&style=flat-square&logo=github)](https://github.com/omrilotan/jonson)
## out-of-the-box, ready-to-use JSON logger
```py
from jonson import loggerlogger.info("Something going as expected", { "host": socket.gethostname() })
logger.warn("Something must have gone terribly wrong")except Exception as e:
logger.error(e, { description: "something descriptive" })
```### Log level
Create logger instance with a minimal log level```py
from jonson import Loggerlogger = Logger("warn")
logger.info("Something going as expected", { "host": socket.gethostname() }) # ignored
logger.warn("Something must have gone terribly wrong") # sent
```#### Log levels hirarchy
A few synonyms are available for convenience
1. `trace`, `verbose`
1. `debug`
1. `info`, `log`
1. `warn`
1. `error`
1. `critical`, `fatal`, `panic`For example, a logger with log level "warn" will only print logs with level "warn", "error", or "critical".
### Arguments
**Create**: Logger class accepts one or two arguments:1. `{string}` Case insensitive name of **minimal** log level. defaults to `"info"`
1. `{dictionary}` {'Key':'Value'} pairs, optional. Persistent enrichment fields for all log records```py
logger = Logger(os.environ["LOG_LEVEL"], { "host": socket.gethostname() })
```**Send**: Logger functions accept one or two arguments:
1. `{any}` Record's "message" field. Traditionally this would be a string or an exception.
1. `{dictionary}` {'Key':'Value'} pairs, optional. Values should be JSON serializable```py
logger.info("something, something", { dark: "side" })
```