Rich-formatted structured logging for Python with automatic syntax highlighting and beautiful console output.
Project description
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
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file richstructlog4-1.0.0.tar.gz.
File metadata
- Download URL: richstructlog4-1.0.0.tar.gz
- Upload date:
- Size: 122.7 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9455dec2d843f4a639f1bf5b1f5f6d41d83c19a2a63195a82feb291f155f2eb
|
|
| MD5 |
52f5b82bdb4a255a46263f757fbd2faa
|
|
| BLAKE2b-256 |
dcf4a489a64146e8086eb8bbb5121b18a4c1e13218fb03a3e7ca29ed027cb66f
|
File details
Details for the file richstructlog4-1.0.0-py3-none-any.whl.
File metadata
- Download URL: richstructlog4-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b44a87f0ff157a7c9141ffa0e3cd711018ad7a94782332374909c78b24873dfd
|
|
| MD5 |
01826beac133457e04ef087acaa93353
|
|
| BLAKE2b-256 |
76bf02506c03b428358005b04d13c8875b71f54b94c1c80835bca2c30d753ee6
|