Created
April 13, 2011 16:22
-
-
Save brainstorm/917863 to your computer and use it in GitHub Desktop.
python logbook mailhandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Small logbook snippet addressing some confusion on record injection | |
import logbook | |
handler = logbook.MailHandler("test@example.com", ['recipient@example.com'], | |
format_string=u'''Subject: [BCBB] {record.extra[run]} \n\n {record.message}''', level='INFO', bubble = True) | |
log = logbook.Logger("mailtest.log") | |
runname = "foobar" | |
with handler.applicationbound(): | |
with logbook.Processor(lambda record: record.extra.__setitem__('run', runname)): | |
log.info("Hello world") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to the documentation, you can inject to:
record.extra['whatever']
In contrast, you should refer to:
record.extra[whatever]
On the format string (note the lack of ' ') :-S