Dorsa Logger Module
Project description
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
logger
object:
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
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
Hashes for dorsa_logger-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4fe77016eb2774d4391a5bc993e2d269474f65da96f62ac07b0d11c5baaf995 |
|
MD5 | 3ed4d7e9604aa5c1d92f751afa2fcf69 |
|
BLAKE2b-256 | d80ffad750a618c1d95f7a39eff127c2c10a5f8ce8d04aa1046133274332cbc7 |