Skip to main content

A custom logger with color support and additional features.

Project description

PyPI version Python Development Status Maintenance PyPI License


custom-python-logger

A powerful and flexible Python logger with colored output, custom log levels, and advanced configuration options.
Easily integrate structured, readable, and context-rich logging into your Python projects for better debugging and monitoring.


🚀 Features

  • Colored Output: Beautiful, readable logs in your terminal using colorlog.
  • Custom Log Levels: Includes STEP (for process steps) and EXCEPTION (for exception tracking) in addition to standard levels.
  • Flexible Output: Log to console, file, or both. Supports custom log file paths and automatic log directory creation.
  • Contextual Logging: Add extra fields (like user, environment, etc.) to every log message.
  • UTC Support: Optionally log timestamps in UTC for consistency across environments.
  • Pretty Formatting: Built-in helpers for pretty-printing JSON and YAML data in logs.
  • Easy Integration: Simple API for getting a ready-to-use logger anywhere in your codebase.

📦 Installation

pip install custom-python-logger

🔧 Usage

Here's a quick example of how to use custom-python-logger in your project:

import logging
from custom_python_logger import build_logger, CustomLoggerAdapter

logger: CustomLoggerAdapter = build_logger(
    project_name='Logger Project Test',
    log_level=logging.DEBUG,
    log_file=True,
)

logger.debug("This is a debug message.")
logger.info("This is an info message.")
logger.step("This is a step message.")
logger.warning("This is a warning message.")

try:
    _ = 1 / 0
except ZeroDivisionError:
    logger.exception("This is an exception message.")

logger.critical("This is a critical message.")

Advanced Usage

  • Log to a file:

    from custom_python_logger import build_logger
    
    logger = build_logger(project_name='MyApp', log_file=True)
    
  • Use UTC timestamps:

    from custom_python_logger import build_logger
    
    logger = build_logger(project_name='MyApp', log_file=True, utc=True)
    
  • Add extra context:

    from custom_python_logger import build_logger
    
    logger = build_logger(project_name='MyApp', log_file=True, utc=True, extra={'user': 'alice'})
    
  • Pretty-print JSON or YAML:

    from custom_python_logger import build_logger, json_pretty_format, yaml_pretty_format
    
    logger = build_logger(project_name='MyApp', utc=True, log_file=True)
    
    logger.info(json_pretty_format({'foo': 'bar'}))
    logger.info(yaml_pretty_format({'foo': 'bar'}))
    
  • use an existing logger (CustomLoggerAdapter) and set a custom name:

    from custom_python_logger import get_logger
    
    logger = get_logger('some-name')
    

logger.debug("This is a debug message.") logger.info("This is an info message.") logger.step("This is a step message.")


---

## 🤝 Contributing
If you have a helpful tool, pattern, or improvement to suggest:
Fork the repo <br>
Create a new branch <br>
Submit a pull request <br>
I welcome additions that promote clean, productive, and maintainable development. <br>

---

## 📄 License
MIT License — see [LICENSE](LICENSE) for details.

---

## 🙏 Thanks
Thanks for exploring this repository! <br>
Happy coding! <br>

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

custom_python_logger-3.0.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

custom_python_logger-3.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file custom_python_logger-3.0.0.tar.gz.

File metadata

  • Download URL: custom_python_logger-3.0.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for custom_python_logger-3.0.0.tar.gz
Algorithm Hash digest
SHA256 ed1b2d6c9c04e6d383494d7cfb98543e2278389919cc41be3d9c786d2f078012
MD5 ce0c52a2e383eb8c9ba7928c1ecef586
BLAKE2b-256 90821dd7fa4d98054e4d405d5e413ce67df1c4164bb7525648c9ae86b5c018ce

See more details on using hashes here.

File details

Details for the file custom_python_logger-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for custom_python_logger-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d034aadda4c1bbdb8f635393503fb64bfc64d2b2cb863b00dc7b1ccf8dd2d66
MD5 30a116031fe0215009d257d5561a4e7b
BLAKE2b-256 6236ce21a828e84181d501d23790fe00198b3f789697f01a6c4cc2aa8b893119

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