Skip to main content

This library standardizes logs and exceptions, ensuring consistent error handling and tracking.

Project description

Dkr Log

This Python library is designed to standardize all logs_exceptions that a Python application may encounter. By implementing a uniform logging system, it ensures consistency in how errors are displayed in the terminal and recorded in an external database. Not only does it enhance readability and debugging efficiency, but it also provides structured error tracking for improved application maintenance.


Installation

pip install dkrlog

Configuration

Before using this library, it is necessary to define specific environment variables that facilitate logging and error tracking:

  • DB_STR: The database connection string used to connect to the destination database.

Additionally, the following function must be executed at the beginning of the code to set up the execution ID, as it will be used in all log entries:

def set_vars(exec_id: str, app_name:str):
    ''' Define o ID da execução '''
    global EXEC_ID, APPLICATION_NAMESPACE, T_CHANNEL, T_URL

    EXEC_ID = exec_id # The execution ID will be used to identify the execution in the destination database.
    APPLICATION_NAMESPACE = app_name # The name by which the application will be identified in the destination database.
    T_CHANNEL = t_channel # The channel to which the error card will be sent.
    T_URL = t_url # The URL of the external Teams webhook to send the error card.

These variables must be populated with the information at the start of the program, ensuring that all logs maintain consistency throughout the application's lifecycle.

Usage

from dkrlog import log_exception, log, set_vars, set_logfile, get_date

# Initialize the execution ID at the beginning of your script
set_vars("your_execution_id", "application_name", "teams_channel", "teams_url")

# Set up a log file (optional but recommended)
set_logfile("execution_log")

# == Logging messages and exceptions ==

# Standard log message:
log("This is an informational message", type="i")

# Logging exceptions within a try-except block:
try:
    # Some operation that may fail
    result = 10 / 0
except Exception as e:
    log_exception("An error occurred while processing", e)

# By following these steps, all logs will be properly recorded in the terminal, saved to log files, and sent to the external logging API

License

This project is licensed under the MIT License.

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

dkrlog-2.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

dkrlog-2.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file dkrlog-2.1.tar.gz.

File metadata

  • Download URL: dkrlog-2.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dkrlog-2.1.tar.gz
Algorithm Hash digest
SHA256 f76cccc69250d8927cc732282b4a20155491b034413172daced768a1e1c3baf1
MD5 dc2f53386f558121fc2dfb4ce991979d
BLAKE2b-256 693b5d99fad4a6b4b425db85a7923deb7d2fe638d0e20c6b3dccd32b82df5049

See more details on using hashes here.

File details

Details for the file dkrlog-2.1-py3-none-any.whl.

File metadata

  • Download URL: dkrlog-2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dkrlog-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a447d62306099a0d050d7c13c623f8d08f489e541b645359c304f47607f3b19
MD5 2711727947c8355f2c911751318d231f
BLAKE2b-256 7205204b2c14337b4745066367d832bdda91849d725297b625af02fdad3846dc

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