A ready-made configuration for Python's standard logging module.
Call init_logging() once, and the whole project gets colored console output, daily log files, and automatic cleanup.
- Colored console output (DEBUG white, INFO cyan, WARNING yellow, ERROR red, CRITICAL bright red)
STDOUTgets messages up to WARNING,STDERRgets ERROR and above- Daily log files (UTC):
logs/app-YYYY-MM-DD.logfor DEBUG to WARNINGlogs/error-YYYY-MM-DD.logfor ERROR and CRITICAL
- Old logs are deleted automatically (default: older than 30 days), once at startup and then every day
- No need for
logging.getLogger(__name__):logging.info(...)shows the real module name (for exampleapp.bot) instead ofroot - Uncaught exceptions in the main thread and in other threads are logged as errors
- Noisy libraries (
urllib3,aiohttp,selenium,telethon,pyrogram,asyncio,apscheduler) are limited to WARNING - Calling
init_logging()twice is safe: the second call is ignored
- Python 3.11+
- colorama
- APScheduler
Available on PyPI. See release 0.0.2.
pip install loggingsetupWith uv:
uv add loggingsetupThe package name is
loggingsetup, but the import name islogging_setup.
In your main script, call it once:
import logging
from logging_setup import init_logging
init_logging()
logging.info("Hello World!")In every other module, just use the standard logging:
import logging
def run():
logging.info("Bot started")
logging.error("Something went wrong")Example output:
2026-10-20 09:42:16 | INFO | app.bot | Bot started
2026-10-20 09:42:16 | ERROR | app.bot | Something went wrong
logger = logging.getLogger(__name__)still works if you prefer it.
| Parameter | Type | Default | Description |
|---|---|---|---|
directory |
str |
"logs" |
Folder for log files |
enable_console |
bool |
True |
Turn console output on or off |
delete_old_logs |
bool |
True |
Turn automatic cleanup on or off |
days_to_delete_old_logs |
int |
30 |
Delete logs older than this many days |
init_logging(directory="my_logs", enable_console=False, days_to_delete_old_logs=14)logging_setup/
├── __init__.py # exports init_logging
├── my_setup.py # main setup function
├── formats.py # color formatter, rotating handler, module name factory
├── filters.py # level filters, exception hooks
└── cleanup_old_logs.py # background cleanup of old log files
- The module name is calculated from the file path relative to the current working directory. Run your project from its root folder, so
app/bot.pyis shown asapp.bot. - The entry script is shown as
main, not__main__. - Old files are deleted only by the cleanup job, not by
backupCount.
This project is licensed under the MIT License.