Skip to main content

A beautiful and feature-rich logging package using Rich library

Project description

๐ŸŒˆ richcolorlog โ€“ Beautiful, Powerful & Multi-Output Logging for Python

โœจ Log like a pro with emoji icons, syntax highlighting, custom log levels, and support for console, file, RabbitMQ, Kafka, ZeroMQ, Syslog, and databases โ€” all in one package!

PyPI version Python Versions License Downloads Documentation

Screenshot


๐Ÿš€ Features

  • โœ… Rich Console Output with colors, backgrounds, and emoji icons per log level

  • ๐ŸŽจ Syntax Highlighting for code snippets (Python, SQL, JSON, etc.) via lexer='python'

  • ๐ŸŽฏ Custom Log Levels: EMERGENCY, ALERT, NOTICE, FATAL (Syslog-compliant)

  • ๐Ÿ“ฆ Multi-Handler Support:

    • ๐Ÿ–ฅ๏ธ Console (Rich + ANSI fallback)
    • ๐Ÿ“„ File (with level-based formatting)
    • ๐Ÿ‡ RabbitMQ
    • ๐Ÿ“ก Kafka
    • ๐Ÿ“ก ZeroMQ
    • ๐Ÿ“ก Syslog
    • ๐Ÿ—„๏ธ PostgreSQL / MySQL / MariaDB / SQLite
  • ๐Ÿงช Jupyter/IPython Friendly (no async warnings!)

  • ๐Ÿงฉ Full LogRecord Template Support: %(asctime)s, %(funcName)s, %(threadName)s, %(icon)s, etc.

  • ๐Ÿ” Smart Timestamp: Repeated timestamps are hidden (like RichHandler original)

  • ๐ŸŽจ Custom Colors: Set color per level (info_color, error_color, etc.)

  • โš™๏ธ Highly Configurable: icon_first, level_in_message, show_background, etc.

  • ๐Ÿš€ Easy to use - Simple setup with sensible defaults

  • โšก Zero required dependencies (only rich for Rich mode; brokers optional)

  • ๐ŸŽจ Support any terminal - with ansi color Fallback


๐Ÿ“ฆ Installation

Install from PyPI:

pip install richcolorlog

๐Ÿ’ก Optional: Install extras for message brokers:

pip install richcolorlog[rabbitmq,kafka,zmq,db]

Or install from source:

git clone https://github.com/cumulus13/richcolorlog
cd richcolorlog
pip install -e .

Documentations

Documentation

๐Ÿงช Quick Start

Basic Usage (Rich Console)

>>> from richcolorlog import setup_logging

>>> logger = setup_logging(
        name="myapp",
        show_background=True,
        show_icon=True,
        icon_first=True
    )
>>> logger.emergency("This is an emergency message")
    logger.alert("This is an alert message")
    logger.critical("This is a critical message")
    logger.error("This is an error message")
    logger.warning("This is a warning message")
    logger.notice("This is a notice message")
    logger.info("This is an info message")
    logger.debug("This is a debug message")
>>> # output
    ๐Ÿ†˜ [10/04/25 14:12:07] EMERGENCY This is an emergency message
    ๐Ÿšจ [10/04/25 14:12:07] ALERT    This is an alert message
    ๐Ÿ’ฅ [10/04/25 14:12:07] CRITICAL This is a critical message
    โŒ [10/04/25 14:12:07] ERROR    This is an error message
    โ›” [10/04/25 14:12:07] WARNING  This is a warning message
    ๐Ÿ“ข [10/04/25 14:12:07] NOTICE   This is a notice message
    ๐Ÿ”” [10/04/25 14:12:07] INFO     This is an info message
    ๐Ÿชฒ [10/04/25 14:12:07] DEBUG    This is a debug message

>>> FORMAT = "%(icon)s %(asctime)s - %(name)s - %(process)d - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
>>> logger = setup_logging(show_background=True, format_template=FORMAT, name="TEST")
>>> code = """
    def hello():
        print("Hello World")
    """
>>> logger.info(code, lexer='python')
>>> #output
    ๐Ÿ”” [10/04/25 15:12:34] TEST 15448 INFO

    def hello():
        print("Hello World")

>>> logger.debug("SELECT * FROM users", lexer="sql")  # Syntax highlighted!
>>> #output
    ๐Ÿชฒ [10/04/25 15:12:35] TEST 15448 DEBUG                                
    SELECT * FROM users

With Custom Format Template

template = "%(asctime)s | %(levelname)s | %(name)s | %(funcName)s() | %(message)s"

logger = setup_logging(
    name="api",
    format_template=template,
    show_background=False
)

logger.notice("User logged in successfully ๐Ÿ”‘")

Custom Format Template + Icon in Template

FORMAT = "%(icon)s %(asctime)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"

logger = setup_logging(
    name="TEST",
    format_template=FORMAT,
    icon_first=True,           # Icon always at start (overrides template position)
    omit_repeated_times=True   # Hide repeated timestamps
)

logger.info("Hello world")
# Output:
# ๐Ÿ”” [10/06/25 15:30:00] INFO - Hello world (test.py:10)
# ๐Ÿ””                     INFO - Another message (test.py:11)

Show Level in Message (level_in_message=True)

logger = setup_logging(level_in_message=True)
logger.info("This is a message")
# Output: INFO - This is a message

Simple Logger (No Rich, for Jupyter)

from richcolorlog import setup_logging_custom

logger = setup_logging_custom(
    name="notebook",
    show_icon=True,
    icon_first=False,
    show_background=False
)

logger.info("Running analysis in Jupyter ๐Ÿ“Š")

๐ŸŽฏ Advanced Examples

๐Ÿ”Œ Send Logs to Kafka & File Logging

logger = setup_logging(
    name="producer",
    log_file=True,
    log_file_name="app.log",
    kafka=True,
    kafka_host="localhost",
    kafka_port=9092,
    kafka_topic="app-logs",
    level="DEBUG"
)

logger.alert("Critical system event! ๐Ÿšจ")

๐Ÿ—„๏ธ Log to PostgreSQL

logger = setup_logging(
    db=True,
    db_type="postgresql",
    db_host="localhost",
    db_name="logs",
    db_user="admin",
    db_password="secret"
)

logger.emergency("Database connection lost!")

๐ŸŽจ Custom Colors per Level

logger = setup_logging(
    info_color="#00FFAA",
    error_color="bold red on #111111",
    warning_color="yellow",
    show_background=True
)
logger.info("Custom color!")
logger.error("Custom background!")

๐Ÿง  Custom Log Levels

logger.notice("New user registered ๐Ÿ“ข")      # Custom level 25
logger.fatal("Fatal error โ€” shutting down ๐Ÿ’€")  # Level 55
logger.alert("Immediate action required! ๐Ÿšจ")   # Level 59

๐Ÿง  Custom Log Levels (Correct Location!)

# File: test.py
logger = setup_logging(name="test")
logger.emergency("System down!")  # Shows: test.py:5 (not logger.py!)
import logging
logger = logging.getLogger("INHERITANCE")
from richcolorlog import RichColorLogHandler
handler = RichColorLogHandler()
logger.handlers.clear()
logger.addHandler(handler)
logger.propagate = False

logger.emergency("RGBME v0.13.2 - 128x64 Matrix | 1x1 Chain | 12px per LED (REAL) | BrowserAdapter")
logger.alert("RGBME v0.13.2 - 128x64 Matrix | 1x1 Chain | 12px per LED (REAL) | BrowserAdapter")
logger.critical("RGBME v0.13.2 - 128x64 Matrix | 1x1 Chain | 12px per LED (REAL) | BrowserAdapter")
logger.error("RGBME v0.13.2 - 128x64 Matrix | 1x1 Chain | 12px per LED (REAL) | BrowserAdapter")
logger.warning("RGBME v0.13.2 - 128x64 Matrix | 1x1 Chain | 12px per LED (REAL) | BrowserAdapter")
logger.notice("RGBME v0.13.2 - 128x64 Matrix | 1x1 Chain | 12px per LED (REAL) | BrowserAdapter")
logger.debug("RGBME v0.13.2 - 128x64 Matrix | 1x1 Chain | 12px per LED (REAL) | BrowserAdapter")


๐Ÿ› ๏ธ Configuration Options

Parameter Description Default
show_icon Show emoji icons True
icon_first Icon before timestamp True
format_template Log format (supports %(icon)s) None
level_in_message Prefix message with "LEVEL - " False
omit_repeated_times Hide repeated timestamps True
show_background Enable background colors True
..._color Custom color per level (info_color, error_color, etc.) Default
All RichHandler args tracebacks_show_locals, keywords, highlighter, etc. Fully supported

โœ… If format_template contains %(icon)s, the icon is still controlled by icon_first โ€” no duplicates.


๐Ÿฆ Available Lexers

You can use any lexer supported by Pygments for syntax highlighting:

  • "python" - Python code
  • "javascript" - JavaScript code
  • "sql" - SQL queries
  • "json" - JSON data
  • "yaml" - YAML configuration
  • "bash" - Shell scripts
  • And many more...

๐Ÿ‡ Custom Log Levels

richcolorlog adds several custom log levels above the standard CRITICAL level:

Level Numeric Value Description
NOTICE 55 Informational messages
ALERT 60 Alert conditions
CRITICAL 65 Critical conditions
FATAL 70 Fatal errors
EMERGENCY 75 System is unusable

๐Ÿงฉ Supported Log Record Fields in Templates

You can use any standard LogRecord field in your format_template:

%(asctime)s       โ†’ 2025-10-03 14:30:00
%(name)s          โ†’ myapp
%(levelname)s     โ†’ INFO
%(message)s       โ†’ Your log message
%(filename)s      โ†’ app.py
%(lineno)d        โ†’ 42
%(funcName)s      โ†’ main
%(process)d       โ†’ 12345
%(thread)d        โ†’ 67890
%(module)s        โ†’ app
%(pathname)s      โ†’ /path/to/app.py
%(created)f       โ†’ 1728000000.123
%(msecs)d         โ†’ 123
%(relativeCreated)d โ†’ 456
%(processName)s   โ†’ MainProcess
%(threadName)s    โ†’ Thread-1
%(icon)s          โ†’ ๐Ÿž (auto-injected)

โœ… Custom fields from extra={} are also supported!


๐ŸŒ Compatibility

  • โœ… Python 3.8+
  • โœ… Jupyter Notebook / IPython (auto-detects and disables async features)
  • โœ… Terminals (Windows, macOS, Linux)
  • โœ… Docker / CI Environments (falls back to ANSI if needed)

๐Ÿ“š Why Use richcolorlog?

Feature Standard logging rich richcolorlog
Emoji Icons โŒ โŒ โœ…
Custom Levels (NOTICE, ALERT) โŒ โŒ โœ…
Syntax Highlighting โŒ โŒ โœ…
Multi-Output (File + Kafka + DB) Manual โŒ โœ…
Template + Icon โŒ Limited โœ…
Accurate File/Line โœ… โŒ โœ…
Jupyter Safe โŒ โš ๏ธ โœ…
Repeated Timestamps โŒ โœ… โœ…
Custom Format Templates โœ… Limited โœ… + icon support

๐Ÿ™ Acknowledgements

  • Built on top of rich by Will McGugan with ansi color Fallback if no rich installed
  • Icons from EmojiOne

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT ยฉ Hadi Cahyadi


๐Ÿ”— Links


๐Ÿ’ฌ Made with โค๏ธ for developers who love beautiful, informative logs!
โญ Star the repo if you find it useful!

author

Hadi Cahyadi

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

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

richcolorlog-1.44.33.tar.gz (488.3 kB view details)

Uploaded Source

Built Distribution

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

richcolorlog-1.44.33-py3-none-any.whl (267.0 kB view details)

Uploaded Python 3

File details

Details for the file richcolorlog-1.44.33.tar.gz.

File metadata

  • Download URL: richcolorlog-1.44.33.tar.gz
  • Upload date:
  • Size: 488.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for richcolorlog-1.44.33.tar.gz
Algorithm Hash digest
SHA256 3602175df5644bad14829ba487a89a7e1f81f2a69727e0667c3134c7a05a4e8e
MD5 5c231356b6420b48399f2bd1f4c6304c
BLAKE2b-256 436374e6d440329fae2ed64dcff8b9ad00e117b005500f4cbbf604018ca3f341

See more details on using hashes here.

File details

Details for the file richcolorlog-1.44.33-py3-none-any.whl.

File metadata

  • Download URL: richcolorlog-1.44.33-py3-none-any.whl
  • Upload date:
  • Size: 267.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for richcolorlog-1.44.33-py3-none-any.whl
Algorithm Hash digest
SHA256 43e498a22947224a64c280c75b9711be178305e2c99f2ad4dbe8fdb1955be4aa
MD5 5a10734d018691c2abff0db5a74f918c
BLAKE2b-256 58478c1f29fc84b3246970b1ac390aad2a72abc2cdb5df79fb96d49426ed04e4

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