Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old May 16th, 2006, 07:15 PM
fuzzylollipop
Guest
 
Posts: n/a
Default How to log only one level to a FileHandler using python logging module.

I want a FileHandler to only log a single level say for example
logging.INFO, and nothing else.
do I need to create a custom Handler for this or is this doable with
some magic that is not documeneted somewhere?

  #2  
Old May 16th, 2006, 09:35 PM
zacherates@gmail.com
Guest
 
Posts: n/a
Default Re: How to log only one level to a FileHandler using python logging module.

Try looking into logging.Filters:
http://docs.python.org/lib/node358.html

An example:

import logging

class InfoFilter(logging.Filter):
def filter(self, record):
return record.levelno == 20

if __name__ == "__main__":
logger = logging.getLogger()
hdlr = logging.FileHandler("blah.log")
hdlr.addFilter(InfoFilter())
logger.addHandler(hdlr)

logger.exception("ERROR WILL ROBINSON")

Cheers,
Aaron


fuzzylollipop wrote:[color=blue]
> I want a FileHandler to only log a single level say for example
> logging.INFO, and nothing else.
> do I need to create a custom Handler for this or is this doable with
> some magic that is not documeneted somewhere?[/color]

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.