Skip to main content

logging-setup

Python License: MIT Code style Built on

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.

Features

  • Colored console output (DEBUG white, INFO cyan, WARNING yellow, ERROR red, CRITICAL bright red)
  • STDOUT gets messages up to WARNING, STDERR gets ERROR and above
  • Daily log files (UTC):
    • logs/app-YYYY-MM-DD.log for DEBUG to WARNING
    • logs/error-YYYY-MM-DD.log for 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 example app.bot) instead of root
  • 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

Requirements

Installation

pip install git+https://github.com/XEQU4/logging-setup.git

Or copy the logging_setup/ folder into your project.

Quick start

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.

Parameters

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)

Project structure

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

Notes

  • The module name is calculated from the file path relative to the current working directory. If you start the project from another folder, pass the project path to install_module_name_factory(...).
  • The entry script is shown as main, not __main__.
  • Old files are deleted only by the cleanup job, not by backupCount.

Metadata

Release files for loggingsetup 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loggingsetup 0.0.1
File Size Uploaded Provenance
loggingsetup-0.0.1.tar.gz 6.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for loggingsetup 0.0.1
File Interpreter ABI Platform
loggingsetup-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / loggingsetup-0.0.1.tar.gz

Download URL loggingsetup-0.0.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1f082f1d43ac9511d457d9778ec0b5ff3f5bb313639d306e8a83427f404447a0
BLAKE2b-256 checksum
How to use checksums
a5804e1ecac66e2006e663fa9c53cdc4d767b46f2df4e1876e92622e70c6b134
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / loggingsetup-0.0.1-py3-none-any.whl

Download URL loggingsetup-0.0.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d99446eed65126d095dfc95672a46122aa8b8802149a1d1f290e22068b0dda6
BLAKE2b-256 checksum
How to use checksums
ea6c4ab8397128dc11917cef31e65621a4addd3158470a7506567bbdc471c21c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for loggingsetup 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page