pylogd
pylogd is a python interface to logd. It pushes log messages or statistics to logd over a UDP socket.
usage
pylogd ships various utilities to deal with logd, python logging handlers, and a Stats object which makes it trivial to record statistics.
logging
To log to logd using the python logging module, create a new handler with your logd server’s host and port and then set it up as your default logging handler:
from pylogd.handlers import PylogdHandler
handler = PylogdHandler('mylogpath.log', '127.0.0.1', 8126)
logger = logging.getLogger()
logger.setHandler(handler)
Now, subsequent calls to logger.(error|warn|etc) will log to your logd server. If you do this on the root logger (getLogger('base')), it will apply to all subsequently created loggers.
To delete a log, use pylogd.delete_log with the host and port of logd:
from pylogd import delete_log
delete_log('mylogpath.log', host='127.0.0.1', 8126)
stats
To use stats, create a stats handle:
from pylogd.stats import Logd
stats = Logd('127.0.0.1', 8126)
You can also supply an optional prefix which will be prepended to all of your stats, so that multiple applications can use the same logd/graphite server without having to repeate their per-app key for every stats call.
Once you have a Logd object, you can increment & decrment counters (with an optional sample rate):
stats.increment('my.counter')
stats.change_by('my.counter', 10)
stats.decrement('my.counter', 0.05) # only update 5% of the time
You can also set the value of a meter:
stats.set('my.meter', 30)
stats.set('my.meter', 30, 0.25) # only set 25% of the time
There’s a basic time interface as well as a convenient timer interface:
stats.time('my.timer', 11.43) # time manually
# automatically start & stop a timer
stats.timer.start('my.timer')
do_some_timed_operation()
stats.timer.stop('my.timer')
# time this function with a 10% sample rate
@stats.timed('my.long_operation', 0.1)
def long_operation():
pass
# accumulate time done doing various similar tasks
stats.timer.start_accumulator('timers.mysql')
do_some_mysql_stuff()
stats.timer.stop_accumulator('timers.mysql')
non_mysql_things()
stats.timer.start_accumulator('timers.mysql')
do_some_more_mysql_stuff()
stats.timer.stop_accumulator('timers.mysql')
# send this timing information to logd
stats.timer.flush_accumulator('timers.mysql')
twisted support
For twisted users, use pylogd.twisted (included) instead of pylogd, and note that log messages and stats will not go to logd until the reactor has been started.
Metadata
Release files for pylogd 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pylogd-0.2.tar.gz | 6.5 kB | Details |
Release files / pylogd-0.2.tar.gz
| Download URL | pylogd-0.2.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b9ad8828833b6f7953b91b30654b3c13ac81c9905761ce60a2edbacd175bc60
|
|
BLAKE2b-256 checksum How to use checksums |
a09276e78a5785da00fccc9bbfea30c1fad6287c4068a8e9cf6c69d507c54e7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |