mozilla-services / metlog-py

INACTIVE - http://mzl.la/ghe-archive - Python library for Services metrics logging
36 stars 8 forks source link

adding a logging Handler #11

Closed tarekziade closed 12 years ago

tarekziade commented 12 years ago

I need to intercept logs emited into logging by libraries. (powerhose, circus,etc)

here what I have done:

see: https://github.com/mozilla-services/tokenserver/blob/master/tokenserver/util.py#L83

use case: https://github.com/mozilla-services/tokenserver/blob/master/tokenserver/__init__.py#L33

Should I push a pull request ?

tarekziade commented 12 years ago

the markup has screwed the second link. Should be init .py

tarekziade commented 12 years ago

Of course I'd do a new method in the client rather than a separate function, Something like:


def _get_handler(self):
    if self._handler is None:
        self._handler = MetlogHandler(self)
        self._handler.setLevel(logging.DEBUG)
    return self._handler

def hook_logger(self, name):
    logging.getLogger(name).addHandler(self._get_handler())
crankycoder commented 12 years ago

i've taken your MetlogHandler and the hook and integrated it into metlog on a branch @ https://github.com/mozilla-services/metlog-py/commit/0bf8b1bce54bf214c18d3c034d42811fde8e139c

crankycoder commented 12 years ago

this is merged into master now