Skip to main content

Logging decorators (file or email)

Project description

General Purpose

The package holds two decorators that can wrap a python function and save the details of it's execution into a log. The details include the name of the function, args and kwargs and what did the function return. This is achieved by means of redirecting stderr and stdout to a file or an email (depending on which decorator is used)

@log - decorator save the log into a file. A relative path: 'output/log.txt' is used by default. Does not require preliminary setup in "config.py" unless another output directory wanted.

@email_log - decorator send the log by email. The usage require SMTP server to be configured at "config.py".

Package Composition

config.py

The setup and configuration file with constants used in the logger.

LOG_FILE:     The path to a log saved by @log decorator. 'output/log.txt' is used by default.

SENDER:       The sender's email will be displayed in the From: field (in the body of the letter).
              May be helpful to specify an email to receive email replies from log recipients.
              Actual email that sends out the letter depend strongly on SMTP server policy.
RECEIVER:     An email where the logs will be sent.
MAIL_SERVER:  A functioning and adjusted SMTP server.
PORT:         SMTP port (an integer)
USERNAME:     SMTP username (received from SMTP server. Frequently - a sender's email)
PASSWORD:     SMTP password (received from SMTP server. Frequently - a sender's password)

SUGGESTION: The package was tested with AWS "Simple Email Service" SMTP provider (https://aws.amazon.com/ses/).

logger.py

The decorators themselves are described in this file. If the output format needs modification, the f-strings in decorators can be modified here.

Operation Manual

To use the package follow the steps:

  • pip install logger_via
  • modify SMTP details in "config.py"
  • from logger import log / from logger import email_log
  • wrap the functions with @log / @email_log

License

The package designed by Vladimir Iakimenko (https://github.com/VladIakimenko).
Free for distribution, modification or contribution.
With feedback address to v_yakimenko@inbox.ru

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

logger_via-1.0.2.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file logger_via-1.0.2.tar.gz.

File metadata

  • Download URL: logger_via-1.0.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for logger_via-1.0.2.tar.gz
Algorithm Hash digest
SHA256 5503a781e845d3105d0186eacd534a35a2a1dc2bbe8caa0222f151115a70b49a
MD5 341ec08c95c721bf0e15d5bccc140278
BLAKE2b-256 2857eade31eafa096fdfb3f91b32bfb33b2640efcc0e74d4abd32573faab0116

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