tags:

views:

44

answers:

2

Currently, I have osmething like this in all of my classes:

# Import logging to log information
import logging

# Set up the logger
LOG_FILENAME = 'log.txt'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)

This works well, and I get the output I want, but I would really like to have all this sort of information in one place, and be able to just do something like import myLogger and then start logging, and then hopefully be able to just go into that file and turn off logging when I need an extra performance boost.

Thanks in advance

+2  A: 

To disable all logging from the root logger (which is all you're setting up with basicConfig),

logging.getLogger().setLevel(logging.CRITICAL)

If you want, you can encapsulate that into a function of your myLogger module, but that hardly seems worth it.

Alex Martelli
Python gave me an error with the `getHandler()` call: module object has no attribute gethandler.
mellort
Oops, typo/thinko -- I meant `getLogger` of course, let me edit to fix (sorry!).
Alex Martelli
+2  A: 

To simply the setting up of logging, check out logging.config.

To disable logging, you could use the command

logging.disable(logging.CRITICAL)
unutbu