Skip to main content

Nonblocking Logging Handler for Python Logging

Project description

Nonblocking Log Handler
-----------------------

Provides a NonblockingLogHandler class consistent with the Python logging
subsystem.

This handler acts as a proxy for the another log handler that may be slow
to execute: e.g. the SMTPHandler, SocketHandler, SysLogHandler - especially
when they are talking to remote servers.

If you have a real-time system (i.e. one where a late response is a wrong
response) and you are sending log messages via email, http, syslog, etc.,
you should consider using this module to protect against unexpected delays.

It is intended to be a drop-in replacement (see provisos below) for your
proxied handler. Unlike the proxied handler, this handler which returns
quickly, and executes the actually logging in the background, in a separate
thread.

Provisos:

* If you pass an objects to the logging functions, be aware that their
__str__() functions should be fast. I/O bound str() calls are outside the
scope of this module.

Execution of str() functions on message parameters and string formatting
is done immediately, in the calling thread. This is to guarantee both
the thread-safety of the logged objects and also that the log shows the
object's values at the time of the call, not the time of the emit.

* If you subclass from Formatter, note that it will not have the user
parameters from the logging call passed to it. It will only receive the
resulting message string formatted according to the client's wishes. It
can still format dates, threadnames, levels, etc.

* If you subclass from Filter, be aware that they should be fast. I/O-bound
filters are outside of the scope of this module.

* Clients should not directly call format() or emit() on the
NonblockingLogHandler class. Consider them private.

* Once the NonblockingLogHandler handler is initialised, any further calls
to setLevel(), addFilter and removeFilter() made on the delegated handler
are ignored by the proxy handler. Conversely, the delegated handler is
not informed of calls made on the NonblockingLogHandler instance.

Best practice would be to only update the NonblockingLogHandler handler,
and not use the values stored in the delegated handler.

* If the close() method is called on the NonblockingLogHandler handler,
there is no need to call close() on the delegated handler; it will be
called when the delegated handler is no longer required.

Example usage:
nonblocking_email_handler = nonblockingloghandler.NonblockingLogHandler(
logging.SMTPHandler(
"localhost", "logging_system@example.com",
"admin@example.com", "Log message")
)
db_logger = logging.getLogger("database")
database_logger.addHandler(nonblocking_email_handler)

# This operation will return immediately, before email is sent.
db_logger.critical("Database corrupted")

nonblocking_email_handler.close()

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

nonblockingloghandler-1.1.0a5.zip (36.1 kB view details)

Uploaded Source

Built Distribution

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

nonblockingloghandler-1.1.0a5-py2.7.egg (12.6 kB view details)

Uploaded Egg

File details

Details for the file nonblockingloghandler-1.1.0a5.zip.

File metadata

File hashes

Hashes for nonblockingloghandler-1.1.0a5.zip
Algorithm Hash digest
SHA256 9153d8cfcbfa7395d5a5b3ba9cce86327edbc1d91bade95fba4a056f85920d5e
MD5 b053612c1b7877414a47c9fbb422bb6e
BLAKE2b-256 08a827a98ee03b2ec0f985e20799369dcab5a37d4d6468493e2da751b0635672

See more details on using hashes here.

File details

Details for the file nonblockingloghandler-1.1.0a5-py2.7.egg.

File metadata

File hashes

Hashes for nonblockingloghandler-1.1.0a5-py2.7.egg
Algorithm Hash digest
SHA256 767b5afeeb63fb5675b2186410322b8781f0e16093bd8a96a04f7a00a5670671
MD5 89818de541d790643d3641aa612c800b
BLAKE2b-256 75e5e2e5308686f9db736239f8701d142cf68015056377b1512a4b3f76092155

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