A powerful Python logging library with custom levels and colored output support
Project description
loggpy
A powerful and flexible Python logging library that extends the standard logging module with custom log levels and colored output support.
Features
- Custom log levels (NOTICE, SPAM, SUCCESS, VERBOSE, LOGKEY)
- Colored output support using
coloredlogs - Blacklist functionality to suppress specific loggers
- Customizable color schemes and formats
- File and console logging support
Installation
pip install loggpy
Basic Usage
from loggpy import Logger
import logging
# Basic setup with console output
Logger.mount(level=logging.INFO)
log = Logger(__name__)
# Use standard log levels
log.debug("Debug message")
log.info("Info message")
log.warning("Warning message")
log.error("Error message")
# Use custom log levels
log.notice("Notice message")
log.spam("Spam message")
log.success("Success message")
log.verbose("Verbose message")
log.logkey("API Key: xyz123") # For logging sensitive or key information
Advanced Configuration
Logging to File
from pathlib import Path
from datetime import datetime
# Log to both console and file
Logger.mount(
level=logging.DEBUG,
HandlerFilename=Path("logs/app.log"),
)
Dynamic Log File Names
Logger.mount(
level=logging.INFO,
HandlerFilename=Path(
f"logs/app_{datetime.now().strftime('%Y-%m-%d_%H_%M_%S')}.log"
)
)
Blacklisting Loggers
# Suppress logs from specific modules
Logger.mount(
level=logging.INFO,
blacklist=[
"filelock",
"oauthlib",
"google",
"charset_normalizer"
]
)
Custom Color Schemes
Logger.mount(
level=logging.INFO,
field_styles={
"asctime": {"color": 35},
"name": {"color": 197},
"levelname": {"color": 244, "bold": True},
},
level_styles={
"spam": {"color": "green", "faint": True},
"debug": {"color": 69},
"verbose": {"color": "blue"},
"info": {},
"notice": {"color": "magenta"},
"warning": {"color": "yellow"},
"success": {"color": 67, "bold": True},
"error": {"color": "red"},
"critical": {"color": "red", "bold": True},
}
)
Log Levels
| Level | Value | Description |
|---|---|---|
| SPAM | 5 | Even more detailed than DEBUG |
| VERBOSE | 15 | Between DEBUG and INFO |
| LOGKEY | 21 | Important key information or sensitive data |
| NOTICE | 25 | Normal but significant events |
| SUCCESS | 35 | Successful operations |
Full Example
from loggpy import Logger
import logging
from pathlib import Path
def setup_logging(debug_mode=False):
# Configure logging with custom settings
Logger.mount(
level=logging.DEBUG if debug_mode else logging.INFO,
HandlerFilename=Path("logs/app.log"),
blacklist=["filelock", "oauthlib"],
field_styles={
"asctime": {"color": 35},
"name": {"color": 197},
"levelname": {"color": 244, "bold": True},
},
level_styles={
"spam": {"color": "green", "faint": True},
"debug": {"color": 69},
"verbose": {"color": "blue"},
"success": {"color": 67, "bold": True},
}
)
return Logger(__name__)
# Initialize logger
log = setup_logging(debug_mode=True)
# Example usage
log.spam("Starting application initialization...")
log.debug("Loading configuration...")
log.verbose("Configuration loaded successfully")
log.info("Application started")
log.notice("New user connected")
log.logkey("Session token: 8f7d56a2-bc4d-4c12-a891-45e70542b21f")
log.success("Transaction completed successfully")
log.warning("High memory usage detected")
log.error("Failed to connect to database")
log.critical("System shutdown initiated")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built on top of Python's standard
loggingmodule - Uses
coloredlogsfor terminal color support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loggpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: loggpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b52bc80470d1e3e5949286c2514f8ae4279e721015cb41295ed2c4e82f17a443
|
|
| MD5 |
2def3f81bb172da99ec7dd37f8bc980a
|
|
| BLAKE2b-256 |
9f5cc0ee7c6f0cdb0f429db39b772b0a08c476cb9fa049969f594405693fd0d9
|