richstructlog4
Structured logging with structlog, rendered for humans with rich.
richstructlog4 gives you:
- Readable console output with timestamps, levels, and key/value fields.
- Stream routing:
WARNINGand above go tostderr, everything below goes tostdout. - Optional file logging: if you pass
log_file, all logs are also written to that file in a plain, ANSI-free format.
Requirements
- Python: 3.8+
- Dependencies:
structlog,rich
Install
From PyPI:
pip install richstructlog4
From Git:
pip install git+https://github.com/MapIV/richstructlog4
Quick start
from richstructlog4 import Logger
log = Logger(log_level="INFO")
log.info("server started", host="127.0.0.1", port=8080)
log.warning("disk space is low", path="/var")
Console routing (stdout vs stderr)
- stdout: levels below
WARNING - stderr:
WARNINGand above
This is useful for CLI tools and scripts where you want to pipe normal output but keep warnings/errors separate.
File logging (plain text)
Pass log_file to also write every event to a file. The file output is plain text (no ANSI escape codes).
from richstructlog4 import Logger
log = Logger(log_file="app.log", log_level="DEBUG")
log.debug("debug goes to file")
log.info("info goes to stdout and file")
log.error("error goes to stderr and file")
Structured fields
Add extra fields as keyword arguments. They are shown as key/value pairs in console output and included in file logs.
log.info("user login", user_id="123", ip="192.168.1.1")
log.error("db connection failed", retry_count=3, database="users")
Rich markup and highlighting
Console output supports Rich markup in message strings.
log.info("Here are rich text markup examples:")
log.info(" - We are hiring. Visit our [link=https://map4.jp]website[/link]!")
log.warning(" - We are going to have a problem")
log.error(" - [bold red]ALERT![/bold red] Something happened")
It also highlights common patterns (HTML/XML, IPs, MACs, UUIDs, literals, numbers, paths, URLs).
log.info("The following texts are automatically highlighted:")
log.info(" - XML/HTML: `<tag>content</tag>`")
log.info(" - IP addresses: `192.168.1.1`, `2001:db8::1`")
log.info(" - MAC addresses: `00:1B:44:11:3A:B7`")
log.info(" - UUIDs: `123e4567-e89b-12d3-a456-426614174000`")
log.info(" - Python literals: `True`, `False`, `None`")
log.info(" - Numbers: `42`, `3.14`, `1+2j`")
log.info(" - Paths: `/usr/local/bin`")
log.info(" - URLs: `https://map4.jp`")
Development
This project uses uv for running tools.
uv run ruff check
uv run ty check
uv run pytest --cov
License
MIT
Metadata
Release files for richstructlog4 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| richstructlog4-1.0.1.tar.gz | 126.5 kB | Without provenance | Details for richstructlog4-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| richstructlog4-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for richstructlog4-1.0.1-py3-none-any.whl |
Total release size: 136.4 kB
Release files / richstructlog4-1.0.1.tar.gz
| Download URL | richstructlog4-1.0.1.tar.gz |
|---|---|
| Size | 126.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0be0995b42e4a1d861874e3d68eec41bdceea7af406e68ad34a9b61640d4e83e
|
|
BLAKE2b-256 checksum How to use checksums |
a29b1effa02ee68f6ca1ccca42733fff01b456c91592bd894c137bc84a637efa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / richstructlog4-1.0.1-py3-none-any.whl
| Download URL | richstructlog4-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47d70287ea87805b5d45e37d6b2887f2c8949d9d6dc9d947ed8646ce561ee27a
|
|
BLAKE2b-256 checksum How to use checksums |
31291ad27cecc7db3194bb3a6b3eefd78ee595b92a25c403780a92b7071aac34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for richstructlog4 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.