negogv-log 🪵🎨
A lightweight, highly readable Python logging library featuring colorized console output, split file logging by severity, custom multiline formatting, and exception location reporting.
📖 Overview
negogv-log is a Python logging utility designed to simplify application logging. It provides out-of-the-box colorized console formatting using ANSI escape codes, separate log file outputs based on severity levels (low_lvl.log vs high_lvl.log), automatic multiline message indentation, and concise exception tracing with source code line locations.
Whether building CLI tools, background workers, or multi-module Python projects, negogv-log ensures log readability in both interactive terminals and log files.
✨ Features
- 🎨 Colorized Console Output: ANSI-colored console logs tailored to log severity (DEBUG, INFO, WARNING, ERROR, CRITICAL).
- 📁 Dual-Level Split File Logging:
low_lvl.log: Captures DEBUG and INFO level logs.high_lvl.log: Captures WARNING, ERROR, and CRITICAL level logs.
- 📄 Smart Multiline Formatting: Automatically indents multiline log messages in log files for clean parsing.
- 🔍 Source Code Origin Tracking: Displays timestamp, level, source filename, and line numbers.
- 🚫 Console Level Exclusion: Exclude specific log levels from printing to console output while preserving file logging.
- 💥 Concise Exception Tracing:
log_exception()helper extracts and displays exception names, source filenames, line numbers, and error messages cleanly.
🗂️ Repository Structure
negogv_logger/
├── negogv_log/ # Core Package Module
│ ├── __init__.py # Package exports (setup_logger, log_exception, formatters, filters)
│ └── logger.py # Main implementation of loggers, formatters, filters & color schemes
│
├── tests/ # Test Suite Directory
│ ├── __init__.py # Test package initialization
│ └── test_model.py # Unit tests for CustomFormatter and CustomFileFormatter
├── examples/ # Minimal runnable usage examples
│
├── LICENSE # MIT Open Source License
├── pyproject.toml # Build system and PyPI package specifications
└── README.md # Original project documentation
Module Breakdown
negogv_log/logger.py:colour(): Utility function for wrapping strings in ANSI color codes.CustomFormatter: Formatter for colored console log output.CustomFileFormatter: Formatter handling multiline indentation for file logs.MaxLevelFilter: Filter restricting log file entries to a maximum log level (e.g.<= INFO).ExcludeLevelFilter: Filter allowing console exclusions for specified log levels.log_exception(): Helper that sends formatted exception details throughlogging.setup_logger(): Primary factory function initializing handlers, filters, and log file outputs.
tests/test_model.py:TestCustomFormatter: Verifies correct log message and level formatting for console output.TestCustomFileFormatter: Verifies newline replacement and multiline indentation handling.
🚀 Installation
Install directly via pip from PyPI:
pip install negogv-log
Or install from source repository:
git clone https://github.com/negogv/negogv_logger.git
cd negogv_logger
pip install .
🛠️ Usage
Basic Example
from negogv_log import setup_logger
# Initialize logger and specify directory for log files
logger = setup_logger(log_dir="logs")
logger.debug("Debugging application state")
logger.info("Service initialized successfully")
logger.warning("High memory usage detected")
logger.error("Failed to connect to database")
logger.critical("Unrecoverable error encountered!")
Excluding Log Levels from Console
You can filter out specific log levels from the console output while still writing them to log files:
# Exclude INFO messages from stdout
logger = setup_logger(log_dir="logs", exclude_console="INFO")
# Exclude multiple levels
logger = setup_logger(log_dir="logs", exclude_console=["DEBUG", "INFO"])
Exception Logging Helper
Use log_exception() to log caught exceptions with file name and line number context:
from negogv_log import log_exception
try:
result = 10 / 0
except Exception as exc:
log_exception(exc)
📦 Technologies
- Language: Python 3.8+
- Standard Library Modules:
logging,sys,os,unittest,typing - Packaging Standard: PEP 517 / PEP 621 with
setuptools
🔧 Configuration
The setup_logger(log_dir, exclude_console=None) function provides the following default behaviors:
| Parameter | Type | Default | Description |
|---|---|---|---|
log_dir |
str |
Required | Path to folder where high_lvl.log and low_lvl.log are stored. |
exclude_console |
Union[List[str], str] |
None |
Log level(s) to suppress from terminal output. |
Log Files Generated in log_dir
low_lvl.log: StoresDEBUGandINFOmessages formatted withCustomFileFormatter.high_lvl.log: StoresWARNING,ERROR, andCRITICALmessages formatted withCustomFileFormatter.
✅ Requirements
- Python:
>= 3.8 - Dependencies: None (uses standard Python library modules only).
🧪 Testing
Run the test suite using Python's built-in unittest module:
python3 -m unittest discover tests
🤝 Contributing
Contributions are welcome!
- Fork the repository (
https://github.com/negogv/negogv_logger). - Create your feature branch (
git checkout -b feature/NewFeature). - Commit your changes (
git commit -m 'Add NewFeature'). - Push to the branch (
git push origin feature/NewFeature). - Open a Pull Request.
📄 Documentation
- Package source code:
negogv_log/logger.py - Unit tests:
tests/test_model.py
❤️ Acknowledgements
- Built and maintained by Daniel Weber (
daniel.tk@tuta.io). - Inspired by Python
loggingstandard library customization techniques.
📝 Changelog
Project release history from repository commits:
0.1.8— Reworked exception logging, handler lifecycle, validation, non-TTY output, and package documentation.0.1.7— Added console log level exclusion filtering (exclude_console).0.1.6— Bug fixes and stability improvements.0.1.5— Minor patch fixes.0.1.4— Package release updates and metadata refinements.0.1.2— Added exception logger (log_exception) and ANSI console color support.Initial— Initial package setup and split log file handlers.
Metadata
Release files for negogv-log 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| negogv_log-0.1.8.tar.gz | 9.7 kB | Without provenance | Details for negogv_log-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| negogv_log-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for negogv_log-0.1.8-py3-none-any.whl |
Total release size: 18.0 kB
Release files / negogv_log-0.1.8.tar.gz
| Download URL | negogv_log-0.1.8.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3568b9b9f2662a0c0113c0013d6eb564deddb78a2a72e25fe623e1bc0c6c4c6d
|
|
BLAKE2b-256 checksum How to use checksums |
ee1c2f179b7af60c4bb4686d69105ac5c46293d826f2a979f2be647a148a0393
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / negogv_log-0.1.8-py3-none-any.whl
| Download URL | negogv_log-0.1.8-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b24c45ca2a4ac0cb65c4df9ab85512ccc2715be0cb04bc2fb4e624ca02bfbaf7
|
|
BLAKE2b-256 checksum How to use checksums |
aa03ee86131569a48bfe761b56ff1df5aeed21659797af088e2b0f7c30420bff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for negogv-log 0.1.8
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.