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.5.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distributions

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

seed_papertrail-1.5.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

seed_papertrail-1.5.0-py2-none-any.whl (6.5 kB view details)

Uploaded Python 2

File details

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

File metadata

File hashes

Hashes for seed-papertrail-1.5.0.tar.gz
Algorithm Hash digest
SHA256 ab060f9df775548c00ac31b29adecadc54dc381c0489f3bb7b821ecc673b5d89
MD5 f10964e64c52cc088ef5b15d11a72838
BLAKE2b-256 201dd3363d11c0c37a17b8e58bc40c78c11c1ce8a3330364a1d2c42309d91cb4

See more details on using hashes here.

File details

Details for the file seed_papertrail-1.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for seed_papertrail-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9929e79766c6a0fc74371df174874af2ae86aebe8179c9beed531b074f07b739
MD5 b274cf7bcb91dab27a6271b73543bc21
BLAKE2b-256 92833b1f923308ef7a470a2711cab95e8749de56a6a5a9938c267f6c4e790dc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for seed_papertrail-1.5.0-py2-none-any.whl
Algorithm Hash digest
SHA256 747219dea5f5df297bc8bb8eee53ccf3ea67f171d8035adcf00b3a3c0944fa3e
MD5 b6e90273a3ef8de096dd5138508391c7
BLAKE2b-256 0431f4e2a1d291ae74b09c55229a81326a3fbeedab4a7116a55d33b668fa2b72

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