Skip to main content

A utility for logging events in Python projects

Project description

python-logging

The log_event function is a utility for logging events in Python projects. It provides a consistent and flexible way to log successes, errors, and other events, and supports multiple output options such as logging to a file or pushing the logs to Elasticsearch.

Features


-  Logs events with the following fields: message, function name,
   project name, version, and status (success or error).
-  Optionally logs error tracebacks in case of errors.
-  Supports logging to a file, with the option to specify the file name
   and log rotation settings.
-  Supports logging to Elasticsearch, with the option to specify the
   Elasticsearch host and port, and other connection settings.
-  Provides a generalized function that can be easily integrated into
   any Python project.

Installation

To install the log_event function, you will need to install the following dependencies: - logging: A built-in Python library for logging events. - traceback: A built-in Python library for printing stack traces in case of errors. - uuid: A built-in Python library for generating unique IDs. - elasticsearch: A third-party library for pushing logs to Elasticsearch. - You can install these dependencies by running the following command:

.. code:: bash

pip install -r requirements.txt

Usage


To use the log_event function, you will need to import it into your
Python code and call it with the appropriate arguments. Here is an
example of how to log a success event:

.. code:: python3

   from log_event import log_event

   log_event('success', "Test message", function_name='test_function', project_name='test_project', version='1.0.0')

This will log a success event with the message ‘Test message’, the
function name ‘test_function’, the project name ‘test_project’, and the
version ‘1.0.0’. To log an error event, you can pass the error argument
with an Exception object:

.. code:: python3

   from log_event import log_event

   try:
       # Some code that may throw an exception
       raise Exception('Test error')
   except Exception as e:
       log_event('error', "Test error", function_name='test_function', error=e, project_name='test_project', version='1.0.0')

This will log an error event with the message ‘Test error’, the function
name ‘test_function’, the project name ‘test_project’, and the version
‘1.0.0’. The error traceback will also be logged.

To log to a file, you can pass the save_to_file argument with a value of
True and the file_name argument with the desired file name:

.. code:: python3

   from log_event import log_event

   log_event('success', "Test message", function_name='test_function', project_name='test_project', version='1.0.0', save_to_file=True, file_name='test.txt')

This will log the event to the file ‘test.txt’.


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

a8logging-1.0.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

a8logging-1.0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file a8logging-1.0.1.tar.gz.

File metadata

  • Download URL: a8logging-1.0.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for a8logging-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1dc2ce5ff671b3f8ff19240e4249eefa91fb7c96a1f1519b5626b99529a0ae2d
MD5 a78ce36703dbd4a607398875015b622f
BLAKE2b-256 cfe567840eec3dccbaf91f3df5e8e4e0d4616304026428d3113cd3b72a8a48b9

See more details on using hashes here.

File details

Details for the file a8logging-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: a8logging-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for a8logging-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 37ddbbaf4e5751a378aa065e97f3431d39921de68bb4a1f39dec4500cdf4c787
MD5 f30b6c986acebf9f3a33fb690c3539cd
BLAKE2b-256 aa0253fedfe4b5121530c46de3d2a799040fc58bb7d7a5fe92c1f0fa423b832b

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