Configuration
RichColorLog provides extensive configuration options for customizing your logging setup.
setup_logging() Parameters
The main setup_logging() function accepts the following parameters:
Basic Parameters
Parameter |
Default |
Description |
|---|---|---|
|
|
Logger name. If None, returns root logger |
|
|
Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
|
|
Enable/disable logging output |
Display Options
Parameter |
Default |
Description |
|---|---|---|
|
|
Show background colors for log levels |
|
|
Show emoji icons for log levels |
|
|
Place icon before timestamp (vs. after message) |
|
|
Show timestamp in log output |
|
|
Show log level name |
|
|
Show file path and line number |
|
|
Hide repeated timestamps |
Format Options
Parameter |
Default |
Description |
|---|---|---|
|
|
Custom format string (see Format Templates) |
|
|
Time format string or callable |
|
|
Include level name in message text |
|
|
Enable Rich markup in messages |
Syntax Highlighting
Parameter |
Default |
Description |
|---|---|---|
|
|
Pygments lexer name for syntax highlighting |
|
|
Pygments theme for syntax highlighting |
|
|
Render emoji in messages |
Custom Colors
Override default colors for each log level:
logger = setup_logging(
debug_color='#FFAA00',
info_color='#00FF00',
warning_color='black on #FFFF00',
error_color='white on red',
critical_color='bright_white on #0000FF',
notice_color='black on #00FFFF',
alert_color='bright_white on #005500',
emergency_color='bright_white on #AA00FF',
fatal_color='blue on #FF557F',
)
Format Templates
Use format templates to customize log output structure:
Available Placeholders
Placeholder |
Description |
|---|---|
|
Timestamp |
|
Logger name |
|
Level name (DEBUG, INFO, etc.) |
|
Numeric level value |
|
Log message |
|
Source filename |
|
Line number |
|
Full path to source file |
|
Function name |
|
Module name |
|
Process ID |
|
Process name |
|
Thread ID |
|
Thread name |
|
Emoji icon for level |
Example Templates
# Simple format
logger = setup_logging(
format_template="%(levelname)s - %(message)s"
)
# Detailed format
logger = setup_logging(
format_template="%(asctime)s [%(name)s] %(levelname)s: %(message)s (%(filename)s:%(lineno)d)"
)
# With icon
logger = setup_logging(
format_template="%(icon)s %(asctime)s %(levelname)s %(message)s",
show_icon=True,
icon_first=False # Icon position controlled by template
)
Environment Variables
RichColorLog respects several environment variables:
Variable |
Description |
|---|---|
|
Set to |
|
Set to |
|
Set to |
|
Set to disable color output |
|
Terminal type for color detection |
|
Color terminal capabilities |
|
Windows Terminal session (enables truecolor) |
|
Set to |
Example:
# Disable logging
export NO_LOGGING=1
python myapp.py
# Force colors in pipe
export FORCE_COLOR=1
python myapp.py | tee output.log
Configuration Examples
Development Configuration
logger = setup_logging(
name='myapp',
level='DEBUG',
show_background=True,
show_icon=True,
icon_first=True,
show_time=True,
show_path=True,
rich_tracebacks=True,
tracebacks_show_locals=True,
)
Production Configuration
logger = setup_logging(
name='myapp',
level='INFO',
show_background=False,
show_icon=False,
log_file=True,
log_file_name='/var/log/myapp/app.log',
log_file_level='DEBUG',
syslog=True,
syslog_host='logserver.example.com',
)
Minimal Configuration
logger = setup_logging(
level='INFO',
show_time=False,
show_path=False,
show_icon=False,
format_template="%(levelname)s: %(message)s"
)