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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file dorsa_logger-1.0.0.tar.gz.

File metadata

  • Download URL: dorsa_logger-1.0.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for dorsa_logger-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2fb4da4f13dc474d91bc11e5c4eb843bfd7375ab1d614da00bd2be7afbd8f8ff
MD5 9a7639908805997374565c4c01a4bbdf
BLAKE2b-256 70bc6f3c62366686ebd398554ec57d716e4279bd7e42218b02bb51495dd544c4

See more details on using hashes here.

File details

Details for the file dorsa_logger-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dorsa_logger-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for dorsa_logger-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4fe77016eb2774d4391a5bc993e2d269474f65da96f62ac07b0d11c5baaf995
MD5 3ed4d7e9604aa5c1d92f751afa2fcf69
BLAKE2b-256 d80ffad750a618c1d95f7a39eff127c2c10a5f8ce8d04aa1046133274332cbc7

See more details on using hashes here.

Supported by

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