A customized rotational logger with monthly archiving and compression
Project description
SkypoukLogger
A customized rotational logger that prints logs to console and stores them in monthly log files with automatic archiving and compression.
Features
- Dual Output: Logs to both console and file simultaneously
- Monthly Rotation: Creates monthly log files (format:
logs_MM_YYYY.log) - Size-based Rotation: Automatically rotates files when they reach 512 MB
- Automatic Archiving: At the start of each month, previous month's logs are merged and compressed into
.gzfiles - Clean Management: Removes original files after successful archiving
- Type Safety: Full type hints for better IDE support and code reliability
- Exception Handling: Custom exceptions for better error management
Installation
pip install date-aware-logger
Quick Start
from dateawarelogger import SkypoukLogger
# Initialize the logger
logger = SkypoukLogger()
# Log messages at different levels
logger.info("Application started")
logger.debug("Debug information")
logger.warning("This is a warning")
logger.error("An error occurred")
logger.critical("Critical system failure")
Advanced Usage
Custom Log Directory
from dateawarelogger import SkypoukLogger
# Use a custom directory for logs
logger = SkypoukLogger(log_directory="custom_logs")
logger.info("Logging to custom directory")
Error Handling
from dateawarelogger import SkypoukLogger, SkypoukLoggerError
try:
logger = SkypoukLogger()
logger.info("This works fine")
except SkypoukLoggerError as e:
print(f"Logger error: {e}")
if e.original_exception:
print(f"Original cause: {e.original_exception}")
How It Works
File Structure
The logger creates the following structure:
logs/
├── logs_01_2024.log # Current month's log file
├── logs_01_2024.log.1 # Rotated file (when size limit reached)
├── logs_12_2023.log.gz # Previous month's compressed archive
└── logs_11_2023.log.gz # Earlier month's compressed archive
Rotation Logic
- Size-based Rotation: When a log file reaches 512 MB, it's rotated (renamed with
.1,.2, etc. suffix) - Monthly Archiving: At the start of each month:
- All log files from the previous month are merged
- The merged file is compressed into a
.gzarchive - Original uncompressed files are removed
- Backup Count: Maintains up to 10 rotated files per month
Log Format
Each log entry follows this format:
2024-01-15 10:30:45,123 - INFO - Your log message here
2024-01-15 10:30:46,124 - ERROR - Error message here
API Reference
SkypoukLogger
__init__(log_directory: str = "logs")
Initialize the logger.
Parameters:
log_directory(str): Directory where log files will be stored. Defaults to "logs".
Logging Methods
debug(message: str): Log a debug messageinfo(message: str): Log an info messagewarning(message: str): Log a warning messageerror(message: str): Log an error messagecritical(message: str): Log a critical message
SkypoukLoggerError
Custom exception class for logger-related errors.
Attributes:
original_exception: The original exception that caused this error (if any)
Requirements
- Python 3.7+
- No external dependencies (uses only Python standard library)
Development
Setting up Development Environment
# Clone the repository
git clone https://github.com/Skypouk/Rotational-Monthly-Logger.git
cd skypouk-logger
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode with dev dependencies
pip install -e ".[dev]"
Running Tests
# Run tests
pytest
# Run tests with coverage
pytest --cov=dateawarelogger --cov-report=html
Code Quality
# Format code
black dateawarelogger tests
# Lint code
flake8 dateawarelogger tests
# Type checking
mypy dateawarelogger
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for your changes
- Ensure all tests pass and code is properly formatted
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
v1.1.0
- Initial release
- Basic rotational logging functionality
- Monthly archiving and compression
- Console and file output
- Type hints and comprehensive documentation
Support
If you encounter any issues or have questions, please open an issue on GitHub.
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 Distribution
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 date_aware_logger-1.1.0.tar.gz.
File metadata
- Download URL: date_aware_logger-1.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
169e7d8c9068e7f4fd6efe6dd82e96ba9fe7712ba62f04552046a7a949d8379d
|
|
| MD5 |
180850db7804789700470ef8d8c40af2
|
|
| BLAKE2b-256 |
995d3d8eff8c3ebd42c3e97a2f8f00284171e51e13445cbef634d49fee8950e1
|
File details
Details for the file date_aware_logger-1.1.0-py3-none-any.whl.
File metadata
- Download URL: date_aware_logger-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c7b1cf3adf453029529ca5ae776d5ccee8438f3df1f231d09447c293e709994
|
|
| MD5 |
eb8f0ab19a89e60157bebe971b75307c
|
|
| BLAKE2b-256 |
87ca2357d6677ec68a39921ae65b0ab0940f51e662d3156dd2264cf0a62862bf
|