A versatile logging module for Python projects
Project description
RsLogMod
RsLogMod is a Python logging module that helps manage log files with features like log rotation, custom log paths, and log levels. It's designed to be simple to use and configure, emphasizing flexibility.
Table of Contents
Installation
To install the module, use pip:
pip install rslogmod
Getting Started
Here’s a quick example to get you logging:
from RsLogMod import rlog
# Log a simple message
rlog(log_name='my_log', log_level=1, log_entry='This is a log entry.')
# Example output: [INFO] 2024-12-02 13:20: This is a log entry.
Explanation
log_name: The name of the log file (e.g.,my_log).log_level: The log level, where1typically corresponds toINFO.log_entry: The message you want to log.
This will create a log file named my_log.log (if it doesn't already exist) in the configured directory with the entry formatted as shown above.
Log Levels & Prefixes
RsLogMod supports several log levels, each with its own prefix:
0:[DEBUG]- For detailed debugging information.
1:[INFO]- For general information about program execution.
2:[ERROR]- For errors that occur during execution.
3:[CRITICAL]- For critical issues that need immediate attention.
4:[SEC-ALERT]- For security-related alerts.
5:[SEC-BREACH]- For security breaches or serious security issues.
Customization
To customize how RsLogMod operates, such as changing the log file directory, setting the maximum log file size, or enabling log rotation, you can use the RsManager class.
Using RsManager
Here's how you can customize various settings:
Set Log Folder Path
from RsLogMod import RsManager
# Create an RsManager instance
manager = RsManager()
# Set a new log folder path
manager.log_folder_path('/new/log/directory')
# Display the current configuration to verify changes
manager.display()
Set Maximum Log Size
from RsLogMod import RsManager
# Create an RsManager instance
manager = RsManager()
# Set the max size for log files to 20 MB
manager.log_max_size(20)
# Display the current configuration to verify changes
manager.display()
Enable or Disable Log Rotation
from RsLogMod import RsManager
# Create an RsManager instance
manager = RsManager()
# Enable log rotation
manager.log_rotation(True)
# Display the current configuration to verify changes
manager.display()
Explanation
RsManager: This class handles the configuration settings for RsLogMod, such as where log files are stored, how large they can grow before being rotated, and whether log rotation is enabled.log_folder_path(path: str): Sets the directory where logs are saved.log_max_size(mega_bytes: int): Sets the maximum size for log files in megabytes.log_rotation(value: bool): Enables or disables log rotation.
Configuration
RsLogMod uses a configs.json file for settings. Here’s an example:
{
"log_rotation": false,
"max_size_in_mega_bytes": 10,
"out_dir": "/path/to/logs"
}
- log_rotation: Enable or disable log rotation.
- max_size_in_mega_bytes: The maximum size of a log file before it is rotated.
- out_dir: The directory where log files will be stored.
You can update these settings programmatically using the RsManager class, as shown in the examples above.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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
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 RsLogMod-0.1.0.tar.gz.
File metadata
- Download URL: RsLogMod-0.1.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51b2b2d31cd54a842377b280a6bd1e7f26364a3ec6f16fe3a2acb2cd002aea40
|
|
| MD5 |
a75b5efe9663f3953d289f5f6eef832a
|
|
| BLAKE2b-256 |
5b788fbf4542d842b6c81061e029889601ec11e8110e8be69ad51f29d56f3894
|
File details
Details for the file RsLogMod-0.1.0-py3-none-any.whl.
File metadata
- Download URL: RsLogMod-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61b76e2379f355dc00d23961e83ad280ad921c91b6adcf6a699ec2e26f30310b
|
|
| MD5 |
dc3aeb5fa9362d805f7d0cc9e260061c
|
|
| BLAKE2b-256 |
52a2f640dc1dd48c0ad1b89b11fcd58ffd9a952241595dd6b2aa6db5a21e4b18
|