Logging helper library.
Project description
fw-logging
Logging helper module standardizing logging and reducing boilerplate.
Usage
Dev
Add as a poetry
dependency to your project:
poetry add fw-logging
The default config is recommended for development, sending logs to stdout
and
colorizing level names if a TTY is detected.
import fw_logging
fw_logging.setup_logging()
Prod
Production apps should emit JSON-formatted structured logs, which can be enabled
by setting the FW_LOG_FORMATTER=json
environment variable, preferably within a
k8s ConfigMap for applications with a Helm chart.
logformat
fw-logging
comes with a command-line entrypoint called logformat
. This
utility pretty-prints structured JSON log records read from a file or stdin
:
# install globally or in your venv
pip install fw-logging
# format a given file or read from stdin
logformat log.jsonl
cat log.jsonl | logformat
Config
fw_logging
may be further configured using envvars and/or kwargs passed to
setup_logging
or get_log_config
, where keyword arguments take precedence
using the LogConfig
pydantic model. See the most important envvars with their
defaults below or check out fw_logging.py
for more details.
Envvar | Default | Example/alternative |
---|---|---|
FW_LOG_HANDLER |
stdout |
stderr |
FW_LOG_FORMATTER |
text |
json |
FW_LOG_LEVEL |
INFO |
DEBUG |
FW_LOG_LOGGERS |
{"pika":"ERROR"} |
|
FW_LOG_FILTERS |
{"fk1":{"msg":"foo"}} |
Development
Install the project using poetry
and enable pre-commit
:
poetry install
pre-commit install
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for fw_logging-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84ccd3aea8a8d40465aee528af448c068c81a560c21b7dc2220dfd2f3820c5d4 |
|
MD5 | e58e780672aefa6349faa6b69f813e5d |
|
BLAKE2b-256 | 9fca7ba3b54e09f376ec0555519c8c223fe63e60a86f32295bcda218762c6d51 |