Skip to main content

Colourful handlers for Logbook, based on Rich and Journald.

Project description

ChameleonLog Logo

Colourful logging handlers for Logbook.

Made in Vietnam PyPI PyPI - Python Version PyPI - License Common Changelog Documentation Status

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

[12:00:00] INFO     MyApp: Application started successfully    cli-app.py:24
           WARNING  MyApp: This is a warning message           cli-app.py:25
           ERROR    MyApp: An error occurred                   cli-app.py:26

JournaldHandler Usage

For systemd journal integration (Linux only) via journald, use JournaldHandler. Logbook provides two ways to attach extra fields:

Simple logging output:

Journald Simple Output

With extra fields for structured filtering:

Journald Extra Fields Output

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chameleon_log-1.0.0.tar.gz (665.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chameleon_log-1.0.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file chameleon_log-1.0.0.tar.gz.

File metadata

  • Download URL: chameleon_log-1.0.0.tar.gz
  • Upload date:
  • Size: 665.9 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

Hashes for chameleon_log-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ea7924df0630ccc5b7fcb832e1bd54fecec2c636283b7691faedd35e511aa954
MD5 33367db02c550570f1e96ff05b3a6e61
BLAKE2b-256 54c31d7f4c29c11138b949061dc2b214349538e238a2b58b3bf79805828b4e85

See more details on using hashes here.

File details

Details for the file chameleon_log-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: chameleon_log-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 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

Hashes for chameleon_log-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfce0cb6282f7d34c258fc7bcb709786e9a4938bff3b47bdfa7431c03a7ec700
MD5 8c922ea185cb64e349cf20dce3bf97e8
BLAKE2b-256 186abcfeb829d43e61c79d0203dcad51df142a24aeb334929ac9cc01a74a6872

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page