Skip to main content

Logs program flow with decorators

Project description

https://travis-ci.org/EricCrosson/stump.svg?branch=master

What is stump?

Stump:

n. the lower end of a tree or plant left after the main part is removed

Log

n. a portion or length of the trunk or of a large limb of a felled tree

Stump is a logging utility for Python that uses the logging module under the covers. However, a stump is a different part of a tree than a log and as such should be utilized differently. Stump offers various method decorators that really cover all the bases of logging for debugging. Stump’s method decorators are flexible and concise, act as additional documentation, don’t clutter the main code of the method body and accept a natural format string that is easy to form and read.

Installation

The publication of this process is still in the works. Check back shortly.

Usage

Insert the stump library and configure the stump logger

#!/usr/bin/env python
import stump

# configure a logger for stump
import sys
import logging
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger()

stump.configure(logger)

And decorate some methods. Stump allows you to interpolate a string representation of the parameter values to decorated methods by simply wrapping the parameter name in curly braces.

import random
@stump.ret('"Calculating" boost for car {car}')
def car_boost(car):
    return random.random() * 100

@stump.pre()
def ready(): pass
@stump.pre()
def set(): pass
@stump.post()
def go(): pass

@stump.ret('Racing {car}')
def race(car):
    luck = car_boost(car)
    return random.randint(1, round(luck))

ready()
set()
go()
race('wacky')

This example logs the following events

INFO:root:ready:ready...
INFO:root:set:set...
INFO:root:go:go...done
INFO:root:race:Racing wacky...
INFO:root:car_boost:"Calculating" boost for car wacky...
INFO:root:car_boost:"Calculating" boost for car wacky...done (returning 11.857944115557483)
INFO:root:race:Racing wacky...done (returning 2)

License

This code is released under the MIT license.

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

stump-0.11.tar.gz (3.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page