Skip to content

Instantly share code, notes, and snippets.

@radix
Last active December 18, 2015 11:49
Show Gist options
  • Save radix/5778336 to your computer and use it in GitHub Desktop.
Save radix/5778336 to your computer and use it in GitHub Desktop.
def example():
import sys
from twisted.python import log
log.startLogging(sys.stdout)
logger = EventHierarchyLogger("myapp", log)
logger.msg("startup")
# in another module...
logger = logger.specialize("rpc")
logger.msg("got-frag", fragger="dreid", fragee="radix")
# This implementation sucks for a couple of reasons; I think the interface is more important.
class EventHierarchyLogger(object):
def __init__(self, event_base, logger):
self.event_base = event_base
self.logger = logger
def msg(self, event, *args, **kwargs):
event = '.'.join([self.event_base, event])
self.logger.msg(event, *args, **kwargs)
def err(self, event, *args, **kwargs):
event = '.'.join([self.event_base, event])
self.logger.err(self.event_base + event, *args, **kwargs)
def specialize(self, event_segment):
new_event_base = '.'.join([self.event_base, event_segment])
return self.__class__(new_event_base, self)
if __name__ == '__main__':
example()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment