This is the seed-papertrail project.
Project description
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
Release history Release notifications | RSS feed
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.3.tar.gz
(8.8 kB
view hashes)
Built Distributions
Close
Hashes for seed_papertrail-1.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8501d11911e1ffcdefc1592439bdfccf2eb9f461ee711dcb98bd5002eb6977ae |
|
MD5 | 8db93114072cd462e62543589681f8fa |
|
BLAKE2b-256 | 2fe08748b50de84dbedd8f8d734a5f310b7f550a42c585b7396b86a26632c0c1 |
Close
Hashes for seed_papertrail-1.4.3-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19ace243262ea4bf3ccdb4bfdcf1c3e188f3ac047ab8fbd6f18d7dbddc36b119 |
|
MD5 | 1fa8d9eb77b3334ed58a263039debb85 |
|
BLAKE2b-256 | 1f838bbd2e48a20ee92f23a3d8548ee99102a45c149c279788245b54b0fb69b8 |