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.2.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.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dkrlog-2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 c4798fe58de676c0dc7b1c73e37b40707839642a05e313a07df83dc5b3d00e7b
MD5 2b58a861d2429afc10ee75ea1913df5b
BLAKE2b-256 b6b97da5285bfff5c7f951e51ca37024f96914703aa174009f9a13d077efc160

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dkrlog-2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2f71daaeb4268ab19a74d72d87f3f98df1f627b703f95b04b5659ad31bb35a68
MD5 78e196180e4e0286d752938f261e32b7
BLAKE2b-256 9b0639d2e3508dd7196b11a678156e3fbc38c8a62d153fe85c47ca02f2ec86b5

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