Skip to content

Instantly share code, notes, and snippets.

@brainstorm
Created April 13, 2011 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brainstorm/917863 to your computer and use it in GitHub Desktop.
Save brainstorm/917863 to your computer and use it in GitHub Desktop.
python logbook mailhandler
#!/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")
@brainstorm
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment