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:

  • LOGGER_URL: The URL to which logs will be sent.
  • LOGGER_TOKEN: The authentication token used in API requests.

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

    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.

This execution ID and application name 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")

# 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-1.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

dkrlog-1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dkrlog-1.1.tar.gz
Algorithm Hash digest
SHA256 2a37cd9fa97bf59805ed2fcb74b75c781d0b364820dece179b658b395191adfe
MD5 f18aaf8ad6d0b6b17483ac798802df4d
BLAKE2b-256 4f8acf02e727045c95e3a4feeed23d5e2efd51c942213e4e834e4ba5e628257e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dkrlog-1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.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-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8fdfd4e2adb7930665eb52070633cf67b789a13fc69e4dbd54d07b23e3e02cd0
MD5 4012c1c966511610982c48f966b7f117
BLAKE2b-256 f5eacfb4f0ed896b49f4c0a6725c9665be621188168440c750d9176d0fdb86db

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