DivineGift Logger
A flexible and configurable logging package for Python applications with file rotation and command-line configuration support.
Features
- ✅ Easy configuration via code or command-line arguments
- ✅ File rotation with customizable intervals
- ✅ Both file and console logging support
- ✅ Thread-safe implementation
- ✅ Type hints for better IDE support
- ✅ Exception logging with stack traces
Installation
pip install dglog
Basic Usage
Simple console logging
from dglog import get_logger
logger = get_logger()
logger.configure_logger()
logger.info("Application started")
logger.warning("This is a warning")
Configure logger programmatically
from dglog import configure_logger
# Configure with daily file rotation
configure_logger(
log_level="DEBUG",
log_name="app.log",
log_dir="./logs",
when="D",
backup_count=14
)
log_info("This will be logged to file")
Command-line configuration
Run your script with logging parameters:
python your_script.py --log_level DEBUG --log_name app.log --log_dir ./logs
The logger will automatically pick up these parameters.
API Reference
Core Functions
| Function | Description |
|---|---|
get_logger() |
Returns the global logger instance |
configure_logger(**kwargs) |
Configures the global logger |
log_debug(*args, separator=" ") |
Logs debug message |
log_info(*args, separator=" ") |
Logs info message |
log_warning(*args, separator=" ") |
Logs warning message |
log_error(*args, separator=" ") |
Logs error message |
log_critical(*args, separator=" ") |
Logs critical message |
log_exception(*args, separator=" ") |
Logs exception with stack trace |
Logger Class Methods
from dglog import get_logger
logger = get_logger()
# Configuration
logger.configure_logger(
log_level="INFO", # Logging level
log_name=None, # File name (None for console)
log_dir="./logs", # Log directory
when="midnight", # Rotation interval
interval=1, # Rotation frequency
backup_count=7, # Number of backups
formatter=None # Custom formatter
)
# Logging methods
logger.debug("Debug message")
logger.info("Information")
logger.warning("Warning message")
logger.error("Error occurred")
logger.critical("Critical failure")
logger.exception("Exception occurred") # With stack trace
Advanced Examples
Custom Formatter
from logging import Formatter
from dglog import configure_logger
custom_format = Formatter('%(name)s - %(levelname)s - %(message)s')
configure_logger(log_level="DEBUG", formatter=custom_format)
Exception Handling
from dglog import log_exception
try:
1 / 0
except Exception:
log_exception("Division failed")
# Output includes the stack trace
Multiple Arguments
log_info("User", "logged in", "from IP", "192.168.1.1", separator=" | ")
# Output: User | logged in | from IP | 192.168.1.1
Dynamic Configuration
import sys
from dglog import get_logger
logger = get_logger()
if '--debug' in sys.argv:
logger.configure_logger(log_level="DEBUG")
else:
logger.configure_logger(log_level="INFO")
Configuration Parameters
| Parameter | Default | Description |
|---|---|---|
| log_level | "INFO" | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
| log_name | None | Log file name (None for console logging) |
| log_dir | "./logs" | Directory for log files |
| when | "midnight" | Rotation interval ('S', 'M', 'H', 'D', 'midnight', etc.) |
| interval | 1 | Rotation frequency |
| backup_count | 7 | Number of backup files to keep |
| formatter | Default format | Custom log message formatter |
Best Practices
- Early Configuration: Configure the logger at the start of your application
- Proper Log Levels: Use appropriate levels for different situations
- Structured Data: Include context in your log messages
- Exception Handling: Always use
log_exception()for errors - Rotation Policy: Choose appropriate rotation settings based on your needs
License
MIT License - Free for commercial and personal use.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dglog-1.0.0.1.tar.gz
(6.3 kB
view details)
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 dglog-1.0.0.1.tar.gz.
File metadata
- Download URL: dglog-1.0.0.1.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45cfdeb3b2076abc6d27accba3aff570d97b0bc6b8615700154ed76bae60dfa5
|
|
| MD5 |
b17f09cdc55e29f291e78ca0ce99f79d
|
|
| BLAKE2b-256 |
c0c10ac75546a739e3c125dd2fe859a0e796a2e09ee0f3328871aed13da7c101
|
File details
Details for the file dglog-1.0.0.1-py3-none-any.whl.
File metadata
- Download URL: dglog-1.0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c54c28d8652bbac3f70e8153052786ff0c91cbb54d8db65a6cc962095b076f7
|
|
| MD5 |
9ca448c94f6a9ab40aa16efed16f99c2
|
|
| BLAKE2b-256 |
8262634f4b3a0f78f14155dea818b23fd9a9591877e191510bd9052bc79a7667
|