Colourful handlers for Logbook, based on Rich and Journald.
Project description
🦎 ChameleonLog
Colourful logging handlers for Logbook.
ChameleonLog provides colorful, structured logging for Python applications using the Logbook.
📦 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 journald:
pip install chameleon_log[journald]
Or using uv:
uv add chameleon_log --extra journald
This will also install the systemd-python package, requiring systemd-based Linux distros.
🚀 Usage
✨ RichHandler
For development and debugging in terminal environments, use RichHandler for colorful, formatted console output:
import logbook
from chameleon_log import RichHandler
# Create a RichHandler with default settings
handler = RichHandler()
with handler:
logger = logbook.Logger(__name__)
logger.info('Application started successfully')
logger.warning('This is a warning message')
logger.error('An error occurred')
🖼️ Example output
🐧 JournaldHandler
For applications deployed on Linux servers or in production environments, use JournaldHandler to write logs directly to journald, using its native protocol. This provides more efficient troubleshooting capabilities compared to file-based logging or stdout / stderr capture.
Basic usage:
import logbook
from chameleon_log.journald import JournaldHandler
handler = JournaldHandler(syslog_identifier='my-app')
with handler:
logger = logbook.Logger(__name__)
logger.info('Application started successfully')
logger.warning('This is a warning message')
logger.error('An error occurred')
📝 Simple logging output:
🏗️ With extra fields for structured filtering:
Logbook provides two ways to attach extra fields:
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(__name__)
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()
# or
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(__name__)
with Processor(inject_request_context):
logger.info('User logged in') # Fields injected automatically
logger.info('Data processed')
View logs with journalctl:
journalctl -fu my-service
journalctl -t my-app F_USER_ID=123
journalctl -eu my-service -o json
Normally, you view your app logs with -u (unit), the syslog_identifier is helpful if your app scatters across many systemd units, you then can use journalctl -t to view all.
📖 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.2.0.tar.gz.
File metadata
- Download URL: chameleon_log-1.2.0.tar.gz
- Upload date:
- Size: 99.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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 |
8da83affb7b7b37d4e4f0d54c253bea186dbb52841105d7309a9be4074fad8e9
|
|
| MD5 |
a3c024f3e1c611b173aa2a97566a6759
|
|
| BLAKE2b-256 |
2e6aed0682af43f28c43d6a711ab1ed387e9b363ac3f9d14e6868528d9a57fdf
|
File details
Details for the file chameleon_log-1.2.0-py3-none-any.whl.
File metadata
- Download URL: chameleon_log-1.2.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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 |
3f127f0f7cdedd550c634858adc8a60ba6c429b6b1072b8e9520d8234de14f6f
|
|
| MD5 |
833523bea17419214398562f2c059a00
|
|
| BLAKE2b-256 |
06f669455dda491cb9b07c5d96bb3eb890157426969db443b1aa2fbaaa48cfc7
|