Logger
Logger is a Python module that provides a logging functionality with various configuration options. It allows you to log messages to both a file and the console, with different log levels and formats.
Installation
◌Instructions:
1-pip install dorsa_logger (not available yet)
2-clone repository
Documentaion
Sphinx documents are not available yet :(
Quick Start
To use the Logger module, follow these steps:
- Import the module:
import dorsa_logger
- Create a
loggerobject:
logger_obj = dorsa_logger.logger(
main_folderpath="./app_logs",
date_type=dorsa_logger.date_types.AD_DATE,
date_format=dorsa_logger.date_formats.YYMMDD,
time_format=dorsa_logger.time_formats.HHMMSS,
file_level=dorsa_logger.log_levels.DEBUG,
console_level=dorsa_logger.log_levels.DEBUG,
console_print=True,
current_username="admin",
line_seperator='-'
)
- Define a log message:
log_msg = dorsa_logger.log_message(level=dorsa_logger.log_levels.ERROR, message="An error occurred", code="ERR000")
- Start logging messages:
logger_obj.create_new_log(message=log_msg)
5 Customize the logger configuration by changing the parameters passed to the logger constructor or using setter functions of logger object. For example, you can set a different main folder path, log levels, date and time formats, and more. for more detailes see Example1
Predefined Log Messages
You can define and use predefined log messages. To define a log message, follow these steps:
- Define a log message:
key = logger_obj.defined_logs.add_log_message(log_msg, key='MY_KEY')
If you don't define any key, key is assigned automatically.
- logging with defined messages:
logger_obj.create_new_log(message=key)
This will log the predefined message with the specified log level. for more detailes see Example2
Decorators to log a function
You can use decorators to log start, end or exceptions of a function. To use decorators, define your function as follow:
@logger_obj.function_start_decorator()
@logger_obj.function_exception_decorator()
@logger_obj.function_end_decorator()
def test(a, b):
res = a*b + 20 + a**b
print('In the function')
raise Exception('This is a fake exception')
return res
After calling function the start, exceptions and end will be logged with defined messages. you can also specify your own message. for more detailes see Example3
Log Levels
The following log levels are available:
- DEBUG (level 10)
- INFO (level 20)
- WARNING (level 30)
- ERROR (level 40)
- CRITICAL (level 50)
- EXCEPTION (level 60)
You can use these log levels when logging messages to specify the severity of the message.
Date Types
The following date types are available:
- SOLAR_DATE
- AD_DATE
Date Formats
The following date formats are available:
- MMDDYY
- DDMMYY
- YYMMDD
Time Formats
The following date formats are available:
- HHMM
- HHMMSS
- HHMMSSMM
Metadata
Release files for dorsa-logger 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dorsa_logger-1.0.0.tar.gz | 12.1 kB | Without provenance | Details for dorsa_logger-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dorsa_logger-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for dorsa_logger-1.0.0-py3-none-any.whl |
Total release size: 23.3 kB
Release files / dorsa_logger-1.0.0.tar.gz
| Download URL | dorsa_logger-1.0.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fb4da4f13dc474d91bc11e5c4eb843bfd7375ab1d614da00bd2be7afbd8f8ff
|
|
BLAKE2b-256 checksum How to use checksums |
70bc6f3c62366686ebd398554ec57d716e4279bd7e42218b02bb51495dd544c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Release files / dorsa_logger-1.0.0-py3-none-any.whl
| Download URL | dorsa_logger-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4fe77016eb2774d4391a5bc993e2d269474f65da96f62ac07b0d11c5baaf995
|
|
BLAKE2b-256 checksum How to use checksums |
d80ffad750a618c1d95f7a39eff127c2c10a5f8ce8d04aa1046133274332cbc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Security for dorsa-logger 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.