A versatile logging module for Python projects
Project description
RsLogMod
*RsLogMod is a flexible and powerful Python logging module designed to manage log files with features such as log rotation, customizable paths, and various log levels. It is easy to use yet offers extensive customization options.
Table of Contents
- Installation
- Getting Started
- Default Behavior
- Log Levels & Prefixes
- Customization
- Configuration
- License
Installation
Install RsLogMod using pip:
pip install rslogmod
Then import the module:
from RsLogMod import rlog, Configure
Getting Started
Here’s a simple example:
from RsLogMod import rlog, Configure
# Set log folder path (only needed once, saved in config)
Configure.set_log_folder_path('path/to/log/folder')
# Log a message
rlog(log_name='my_log', log_level=1, log_entry='This is a log entry.')
Explanation
log_name: Name of the log file (e.g.,my_log).log_level: Log level (1for INFO,2for ERROR, etc.).log_entry: The message to log.verbose: Optionally setverbose=Trueto print the message to the terminal as well.
Default Behavior
- Log Rotation: Enabled by default (log files rotate when they reach the set max size).
- Log to File and Terminal: Logs are written to the file, and verbose mode controls whether they are printed to the terminal.
- Config Persistence: Once paths are set, they are stored in a config file for future sessions.
Log Levels & Prefixes
RsLogMod supports the following log levels, each with its own prefix:
- 0:
[DEBUG]- Detailed debug information. - 1:
[INFO]- General program execution info. - 2:
[ERROR]- Errors encountered during execution. - 3:
[CRITICAL]- Critical issues that need attention. - 4:
[SEC-ALERT]- Security-related alerts. - 5:
[SEC-BREACH]- Security breaches or serious issues.
Customization
Set Log Folder Path
Configure.set_log_folder_path('/path/to/logs')
Set Archive Folder Path
Configure.set_archive_path('/path/to/archive')
Set Maximum Log Size
Configure.set_log_file_max_size(50) # Max size is set in MB
Enable or Disable Log Rotation
Configure.enable_log_rotation(True) # Enable or disable log rotation
Enable or Disable Verbose Mode
Verbose mode controls whether logs are printed to the terminal. It can be controlled globally via the config or for each individual rlog() call.
Global Verbose Mode
Enable verbose globally, applying to all future log entries unless overridden:
Configure.enable_verbose(True) # Enable terminal printing for all logs
Per-Entry Verbose Mode
Control verbosity per log entry by using the verbose parameter in rlog():
rlog(log_name='my_log', log_level=1, log_entry='This will print to terminal', verbose=True)
Verbose Mode Behavior
- If
verboseis passed inrlog(), it overrides the global config. - If not passed (
None), it falls back to the config file setting. - If both are unset (
None), logs will only be written to the file.
Example Configuration:
{
"log_rotation": true,
"verbose": null,
"max_size_in_mega_bytes": 50,
"log_folder": "path/to/logs",
"archive_folder": "path/to/archive"
}
"verbose": true: Logs print to terminal and file."verbose": false: Logs are only written to the file."verbose": null: Behavior is controlled by the individualrlog()calls.
Display Configuration
Configure.display() # Display the current configuration in JSON format
Configuration
RsLogMod stores its settings in a configs.json file:
{
"log_rotation": true,
"verbose": null,
"max_size_in_mega_bytes": 50,
"log_folder": "/path/to/logs",
"archive_folder": "/path/to/logs/archived"
}
log_rotation: Enables or disables log rotation.verbose: Controls whether logs are printed to the terminal.log_folder: Directory where logs are saved.archive_folder: Directory where archived logs are stored.
Changelog
[Jan 15, 2025]
- Class Name Change: Renamed the
Configureclass toRsConfigfor better clarity and consistency in the codebase. - Deprecation Warning: The
Configureclass is still functional but deprecated. It will be removed in version 2. A deprecation warning will appear when using the old class. - Action Required: Start using
RsConfigin your code to avoid issues in future releases. The old class (Configure) will no longer be available in version 2.
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 Distributions
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-1.1.2.tar.gz.
File metadata
- Download URL: rslogmod-1.1.2.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a967ab5c9d33fe04569997a9b8a8e0245468c30e8bb92570a0beb1bbdb99a58
|
|
| MD5 |
84c2321dc79b1e4ff756b6bc02d7cf39
|
|
| BLAKE2b-256 |
ff551f783b75b94b9f8b6b4c3c5d668dda95fa8b2930881920a3299267dea733
|
File details
Details for the file rslogmod-1.1.2-py3-none-any.whl.
File metadata
- Download URL: rslogmod-1.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f8fcba527ad0389354cc2e000704e93c59a34546068585b3303190419f20e9f
|
|
| MD5 |
b3fec0312a0211a5f4b33d7b6d006664
|
|
| BLAKE2b-256 |
32d2cd0e49c17ee7264a8700418a613609733b9c919389f8ffce0bea4b6be9ac
|
File details
Details for the file RsLogMod-1.1.2-py3-none-any.whl.
File metadata
- Download URL: RsLogMod-1.1.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbec74b090c3743553fba5a06ccd70410f7aa3d13a6b3f19e9d9d11925e8f157
|
|
| MD5 |
8ba2e8c976ba517a3ddda67d231630a4
|
|
| BLAKE2b-256 |
baa01c1cd9cb50eae7d36a420094c5e51206fa6e997b557418d84b6f5d876324
|