Skip to main content

A lightweight Python logging library with sync/async support, colorful terminal output, auto exception capture and zero configuration.

Project description

Quick-Logger-Colorful

A lightweight Python logging tool with colorful terminal output(Otherwise, why would it be called Colorful?), automatic exception capture, sync/async support. Designed for fast integration in Python projects, supporting log grading and date-based log file splitting.

PyPI Version Python Versions License

Features

  • Log Grading: Supports 5 levels - DEBUG(0), INFO(1), WARN(2), ERROR(3), FATAL(4)
  • Colorful Output: Distinct colors for better visibility:
    • DEBUG: Cyan
    • INFO: Green
    • WARN: Yellow
    • ERROR: Red
    • FATAL: Red background + White text
  • Auto Exception Capture: One-line decorator for both sync/async functions, with fatal exception marking
  • Zero Configuration: Automatically creates log directories and configuration files on first run
  • Date-based Splitting: Generates separate log files for each day to avoid oversized files
  • Dual Mode Support: Sync logging (core module) + Async logging (asynclog module)
  • Mode Switch: Toggle debug/production mode with -O command-line argument

Installation

PyPI Installation (Recommended)

pip install quick-logger-colorful

Local Installation

  1. Clone the repository:
    git clone https://github.com/huyuenshen/quick-logger.git
    cd quick-logger
    
  2. Install from source:
    pip install .
    

Quick Start

1. Sync Logging (Core Module)

from quick_logger import Datalog, start_logger

# Initialize logger
logger = Datalog()

# Log messages of different levels
logger.log("This is a DEBUG message", typ=0)
logger.log("This is an INFO message", typ=1)
logger.log("This is a WARN message", typ=2)
logger.log("This is an ERROR message", typ=3)
logger.log("This is a FATAL message", typ=4)  # New FATAL level

# Exception capture with decorator (mark specific exceptions as FATAL)
@start_logger
def test_function():
    logger.log("Running sync test function", typ=1)
    raise KeyError("Critical error (marked as FATAL)")  # Triggers FATAL log

if __name__ == "__main__":
    try:
        test_function()
    except Exception:
        pass

2. Async Logging (asynclog Module)

For asynchronous functions, use the asynclog module to avoid blocking the event loop:

import asyncio
from quick_logger import asynclog

async def async_test_func():
    logger = asynclog.Datalog()
    await logger.log("This is an async INFO message", typ=1)
    await logger.log("This is an async FATAL message", typ=4)  # Async FATAL log
    await asyncio.sleep(1)  # Simulate async work (non-blocking)

# Async decorator with fatal exception marking
@asynclog.start_logger
async def wrapped_async_func():
    await async_test_func()
    raise KeyError("Async fatal error")  # Triggers FATAL log

if __name__ == "__main__":
    asyncio.run(wrapped_async_func())

Mode Switch

  • Debug Mode (Default): Shows all log levels (DEBUG/INFO/WARN/ERROR/FATAL)
    python your_script.py
    
  • Production Mode: Hides DEBUG level (shows INFO/WARN/ERROR/FATAL)
    python your_script.py -O
    

Configuration

Auto-generated Config File

On first run, a configuration file is created at ./Datalog/.config/Config.json with the following default content:

{
    "pattern": "[{time}][{func}][{level}]:{msg}",
    "file": "./Datalog/{date}.log.txt"
}
  • pattern: Log format template (supports {time}, {func}, {level}, {msg})
  • file: Log file path ({date} is replaced with the current date, e.g., 2025-12-25.log.txt)

Custom Log Format

Modify the pattern field to customize the log format, e.g.:

{
    "pattern": "[{time}] [{level}] [{func}] - {msg}"
}

Compatibility

  • Python Versions: 3.7+
  • Platforms: Windows, macOS, Linux, Android (Python compilers like Pydroid)

License

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

Contributing

Issues and pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

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

quick_logger_colorful-0.3.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

quick_logger_colorful-0.3.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file quick_logger_colorful-0.3.0.tar.gz.

File metadata

  • Download URL: quick_logger_colorful-0.3.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for quick_logger_colorful-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b9893460981988a537ad28b89cad45096ea65cd239137c4c3e3d2a21ded97425
MD5 792807d9ff5623d9124563b235d08429
BLAKE2b-256 c2d57324a984ac401e0918c3ebef712c9137985b5d9747f0c2522dfb2ee750a4

See more details on using hashes here.

File details

Details for the file quick_logger_colorful-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for quick_logger_colorful-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f86e5834c659f36624e22bbec57aa6a56185ea5739f312df39d1c9bcec58dd2
MD5 58bac7c1731998f8d79af93f57c59965
BLAKE2b-256 ed2dbd32d922d24d94da7f8f11c80042c94e4b4ee42f945062c9cd4dd6b0e7b1

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