Colourful handlers for Logbook, based on Rich and Journald.
Project description
Colourful logging handlers for Logbook.
ChameleonLog provides colorful, structured logging for Python applications using the Logbook framework.
RichHandler: Beautiful console output with syntax highlighting and tracebacks using the Rich library.
JournaldHandler: Structured logging to systemd journal with automatic level-based coloring and filtering.
Installation
Install ChameleonLog using pip:
pip install chameleon_log
Or using uv:
uv add chameleon_log
Optional Dependencies
To use the JournaldHandler for sending logs to systemd journal (Linux only):
pip install chameleon_log[journald]
Or using uv:
uv add chameleon_log --extra journald
This requires Linux with systemd and installs the systemd-python package.
Usage
Basic usage:
import logbook
from chameleon_log import RichHandler
# Create a RichHandler with default settings
handler = RichHandler()
with handler:
logger = logbook.Logger('MyApp')
logger.info('Application started successfully')
logger.warning('This is a warning message')
logger.error('An error occurred')
Customizing the handler:
# Create a RichHandler with custom settings
handler = RichHandler(
level=logbook.DEBUG,
# Additional Rich-specific options can be added here
)
Example Output
JournaldHandler Usage
For systemd journal integration (Linux only) via journald, use JournaldHandler. Logbook provides two ways to attach extra fields:
Simple logging output:
With extra fields for structured filtering:
Option 1: Use the extra= parameter (simple and direct)
import logbook
from chameleon_log.journald import JournaldHandler
handler = JournaldHandler(syslog_identifier='my-app')
with handler:
logger = logbook.Logger('MyApp')
logger.info('User logged in', extra={'user_id': 123, 'action': 'login'})
Option 2: Use a Processor (for reusable context)
import logbook
from logbook import Logger, Processor
from chameleon_log.journald import JournaldHandler
handler = JournaldHandler(syslog_identifier='my-app')
# Use a Processor to inject context into multiple log records
def inject_request_context(record):
record.extra['user_id'] = 123
record.extra['request_id'] = 'abc-456'
with handler:
logger = logbook.Logger('MyApp')
with Processor(inject_request_context):
logger.info('User logged in') # Fields injected automatically
logger.info('Data processed')
View logs with journalctl:
journalctl -t my-app
journalctl -t my-app F_USER_ID=123
journalctl -t my-app -o json
Documentation
Full documentation is available at: https://chameleon-log.readthedocs.io
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Logo by Freepik.
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 chameleon_log-1.1.0.tar.gz.
File metadata
- Download URL: chameleon_log-1.1.0.tar.gz
- Upload date:
- Size: 381.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","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 |
1a124ecbc0008f3afb9ac75b92d085028193efb38268b5b7f5e5afbff9684eb3
|
|
| MD5 |
3077142eae607a3d28eb14bed4cd9093
|
|
| BLAKE2b-256 |
7ae950c9b6e202b0964e929984c23186dde70e8127ab5963a2f0277b349bb888
|
File details
Details for the file chameleon_log-1.1.0-py3-none-any.whl.
File metadata
- Download URL: chameleon_log-1.1.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","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 |
a3072f9fdb270ed12d5ddaddbbcebff8857e9722a74771da07eac654773c8715
|
|
| MD5 |
c7293357e0c2dff59a9118405bf97830
|
|
| BLAKE2b-256 |
1df32470f90822c2f13e5bcaa5d1dcb63d0a83718b85f91ce760b35353030cea
|