Skip to main content

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:

  1. Import the module:
import dorsa_logger
  1. 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='-'
)
  1. Define a log message:
log_msg = dorsa_logger.log_message(level=dorsa_logger.log_levels.ERROR, message="An error occurred", code="ERR000")
  1. 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:

  1. 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.

  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dorsa_logger-1.0.0.tar.gz (12.1 kB view hashes)

Uploaded Source

Built Distribution

dorsa_logger-1.0.0-py3-none-any.whl (11.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page