Skip to main content

This is the seed-papertrail project.

Project description

https://img.shields.io/travis/praekeltfoundation/seed-papertrail.svg https://img.shields.io/pypi/v/seed-papertrail.svg Code Coverage seed-papertrail Docs

Some utilities to time things and log things.

>>> import logging
>>> formatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s]  %(message)s")
>>> logger = logging.getLogger('papertrail')
>>> consoleHandler = logging.StreamHandler()
>>> consoleHandler.setFormatter(formatter)
>>> logger.addHandler(consoleHandler)
>>> logger.setLevel(logging.DEBUG)

Usage as a function decorator

>>> from seed_papertrail.decorators import papertrail
>>> @papertrail.warn
... def testing(): print 1
...
>>> testing()
1
2017-01-24 11:16:02,100 [MainThread  ] [WARNI]  __main__.testing 0.000021:

One can also specify a custom log message and a sample size argument:

>>> @papertrail.warn('this is likely to explode', sample=0.5)
... def testing(): print 1
...
>>> testing()
1
>>> testing()
1
>>> testing()
1
2017-01-24 11:38:56,068 [MainThread  ] [WARNI]  __main__.testing 0.000018: this is likely to explode
>>> testing()
1
2017-01-24 11:38:59,628 [MainThread  ] [WARNI]  __main__.testing 0.000019: this is likely to explode
>>> testing()
1
>>>

Usage as a context manager

>>> from seed_papertrail.decorators import papertrail
>>> with papertrail.timer('hulloo') as l:
...     l.debug('more logging here!')
...     print 1
...
2017-01-24 11:32:23,109 [MainThread  ] [DEBUG]  more logging here!
1
2017-01-24 11:32:23,115 [MainThread  ] [DEBUG]  0.002581: hulloo, threshold:OK
>>>

You can also specify custom thresholds:

>>> with papertrail.timer('o_O', thresholds={'OK': (0, 0.1), 'FAIL': (0.1, 1000)}):
...     time.sleep(6)
...
2017-01-24 11:45:00,717 [MainThread  ] [DEBUG]  6.000664: o_O, threshold:FAIL

Addtionally the timer function allows one to specify the following keyword arguments:

  • level the logging level, defaults to DEBUG

  • logger the logger to log to, defaults to papertrail

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

seed-papertrail-1.4.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

seed_papertrail-1.4.2-py2-none-any.whl (6.4 kB view details)

Uploaded Python 2

File details

Details for the file seed-papertrail-1.4.2.tar.gz.

File metadata

File hashes

Hashes for seed-papertrail-1.4.2.tar.gz
Algorithm Hash digest
SHA256 a775888884839dd6f66ae9cd6a51bd08df67d65dbe53b241bb688094e4c162c9
MD5 7ad1de416a1b147c71c99afab12f76ba
BLAKE2b-256 bc5b82e8371011e056d1cc0023bf7246e69d5fe08bf320f1fb7a75c3e70809b9

See more details on using hashes here.

File details

Details for the file seed_papertrail-1.4.2-py2-none-any.whl.

File metadata

File hashes

Hashes for seed_papertrail-1.4.2-py2-none-any.whl
Algorithm Hash digest
SHA256 876843fce247de89357a1fbf9beb6d12f5be13ef2335bf5d90d6b6d1eb310603
MD5 fa2f702d78896d7679270ce2d4014732
BLAKE2b-256 9a0551749478472a03bf65daec432642da57707b5f2055e61f647becd879e07e

See more details on using hashes here.

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