Skip to main content

logd python library

Project description


pylogd is a python interface to logd. It pushes log messages or statistics to logd over a UDP socket.


pylogd ships various utilities to deal with logd, python logging handlers, and a Stats object which makes it trivial to record statistics.


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', '', 8126)
logger = logging.getLogger()

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='', 8126)


To use stats, create a stats handle:

from pylogd.stats import Logd
stats = Logd('', 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.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

# time this function with a 10% sample rate
@stats.timed('my.long_operation', 0.1)
def long_operation():

# accumulate time done doing various similar tasks

# send this timing information to logd

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.

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylogd-0.2.tar.gz (6.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page