Skip to main content

Logging utilities to help you over-communicate

Project description

logquacious Documentation Status

Logquacious is a set of simple logging utilities to help you over-communicate. (Logorrhea would’ve been a good name, if it didn’t sound so terrible.)

Good application logging is easy to overlook, until you have to debug an error in production. Logquacious aims to make logging as easy as possible.

Quick start

To get started, first make sure logquacious is installed:

$ pip install logquacious

You’ll also need to set up logging for your application. For this example, we’ll use a really simple configuration:

import logging

logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

The main interface to logquacious is the LogManager, which can be used for normal logging:

import logquacious

log = logquacious.LogManager(__name__)
log.debug('Nothing to see here.')

Due to our simplified logging format defined earlier, that would output:

DEBUG: Nothing to see here.

That isn’t a very interesting example. In addition to basic logging, LogManager has a context attribute for use as a context manager:

>>> with log.context.debug('greetings'):
...    print('Hello!')
DEBUG: Enter greetings
DEBUG: Exit greetings

The same attribute can be used as a decorator, as well:
def divide(numerator, denominator):
    if denominator == 0:
        log.warning('Attempted division by zero. Returning None')
        return None
    return numerator / denominator

>>> divide(1, 0)
INFO: Call `divide()`
WARNING: Attempted division by zero. Returning None
INFO: Return from `divide`

Even better, you can log input arguments as well:, show_kwargs=True)
def greet(name, char='-'):
    msg = 'Hello, {name}!'.format(name=name)
    print(char * len(msg))

>>> greet('Tony', char='*')
INFO: Call `greet('Tony', char='*')`
Hello, Tony!
INFO: Return from `greet`

There’s also a special context manager for suppressing errors and logging:

with log.and_suppress(ValueError, msg="It's ok, mistakes happen"):
    raise ValueError('Test error')
[ERROR] It's ok, mistakes happen
Traceback (most recent call last):
  File "/Users/tyu/code/logquacious/logquacious/", line 103, in and_suppress
  File "scripts/", line 26, in <module>
    raise ValueError('Test error')
ValueError: Test error


The message templates used by LogManager.context can be configured to your liking by passing a context_templates argument to LogManager:

log = logquacious.LogManager(__name__, context_templates={
    'context.start': '=============== Enter {label} ===============',
    'context.finish': '=============== Exit {label} ===============',

with log.context.debug('greetings'):
[DEBUG] =============== Enter greetings ===============
[DEBUG] =============== Exit greetings ===============

The general format for context_templates keys is:


where square-brackes marks optional fields.

CONTEXT_TYPE can be any of the following:

  • function: Template used when called as a decorator.
  • context: Template used when called as a context manager.

LOG_LEVEL_NAME can be any of the following logging levels:

  • INFO

For example, consider the cascade graph for function.start.DEBUG, which looks like:

          /       \
start.DEBUG       function.start
          \       /

The cascade is performed using a breadth-first search. If function.start.DEBUG is not defined, check start.DEBUG then check function.start BEFORE checking start.

The default configuration is:

    'start': 'Enter {label}',
    'finish': 'Exit {label}',
    'function.start': 'Call `{label}({arguments})`',
    'function.finish': 'Return from `{label}`',

Note that custom configuration updates these defaults. For example, if you want to if you want to skip logging on exit for all context managers and decorators, you’ll have set both 'finish' and 'function.finish' to an a None or an empty string.


This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.


0.4.0 (2018-10-05)

  • Fix config override behavior to extend rather than replace default templates

0.3.0 (2018-10-05)

  • Add decorator support for log.and_suppress and log.and_reraise context managers
  • Suppress logging for null/empty log message templates

0.2.0 (2018-10-03)

Changed default templates. In 0.1.0, the templates were:

    'start': 'Start {label}',
    'finish': 'Finish {label}',

These defaults have been changed to:

    'start': 'Enter {label}',
    'finish': 'Exit {label}',
    'function.start': 'Call `{label}({arguments})`',
    'function.finish': 'Return from `{label}`',

0.1.0 (2018-10-03)

  • First release on PyPI.

Project details

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
logquacious-0.4.0-py2.py3-none-any.whl (11.5 kB) Copy SHA256 hash SHA256 Wheel py2.py3
logquacious-0.4.0.tar.gz (23.0 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page