Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A buffered logging handlers that mimics SMTPHandler

Project Description

Buffered SMTP Logging Handler

A library that mimics the standard logging.handlers.SMTPHandler class but sends email messages only when a preconfigured buffer is full or on exit.

Installation and dependencies

Install the program using pip:

pip install buffered_smtp_handler

How to use it

This library offers two classes: BufferedSMTPHandler and BufferedSMTPHandlerSSL.

They accept the same arguments of the standard SMTPHandler class, and also the capacity argument to set the capacity of the buffer (default: 100).

The SSL version is based on the smtplib.SMTP_SSL and avoids to perform StartSSL.

Via code:

>>> import logging
>>> from pierky.buffered_smtp_handler import BufferedSMTPHandler
>>> logger = logging.getLogger("my_app")
>>> logger.setLevel(logging.INFO)
>>> h = BufferedSMTPHandler("smtp.example.com", "from@example.com", ["to@example.com"], "MyApp log", capacity=10)
>>> logger.addHandler(h)
>>> logger.warning("Test")

Via a logging configuration file:

[loggers]
keys=root

[formatters]
keys=simple

[handlers]
keys=stderr,smtp

[logger_root]
level=INFO

handlers=stderr,smtp

[formatter_simple]
format=ARouteServer %(asctime)s %(levelname)s %(message)s

[handler_stderr]
class=StreamHandler
formatter=simple
args=(sys.stderr,)

[handler_smtp]
class=pierky.buffered_smtp_handler.BufferedSMTPHandler
level=WARN
formatter=simple
args=(('smtp.example.com', 25), 'from@example.com', ['to@example.com'], 'MyApp log')

Author

Pier Carlo Chiodi - https://pierky.com/

Blog: https://blog.pierky.com/ Twitter: @pierky

Change log

v0.1.0

First release.

Release History

This version
History Node

0.1.0

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
buffered_smtp_handler-0.1.0.tar.gz
(18.9 kB) Copy SHA256 Hash SHA256
Source None Oct 20, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting