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!
๐ 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
RichHandleroriginal) -
๐จ 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
richfor 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
๐งช 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_templatecontains%(icon)s, the icon is still controlled byicon_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
richby 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
- ๐ฆ PyPI: https://pypi.org/project/richcolorlog/
- ๐ป GitHub: https://github.com/cumulus13/richcolorlog
- ๐ง Author: cumulus13@gmail.com
๐ฌ Made with โค๏ธ for developers who love beautiful, informative logs!
โญ Star the repo if you find it useful!
author
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3602175df5644bad14829ba487a89a7e1f81f2a69727e0667c3134c7a05a4e8e
|
|
| MD5 |
5c231356b6420b48399f2bd1f4c6304c
|
|
| BLAKE2b-256 |
436374e6d440329fae2ed64dcff8b9ad00e117b005500f4cbbf604018ca3f341
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43e498a22947224a64c280c75b9711be178305e2c99f2ad4dbe8fdb1955be4aa
|
|
| MD5 |
5a10734d018691c2abff0db5a74f918c
|
|
| BLAKE2b-256 |
58478c1f29fc84b3246970b1ac390aad2a72abc2cdb5df79fb96d49426ed04e4
|