python logging module problem

Ritesh Raj Sarraf riteshsarraf at gmail.com
Thu Jul 13 06:54:13 EDT 2006


Ritesh Raj Sarraf wrote:
> import os, sys, logging
>
> logger = logging.getLogger("my_app")
>


I tried this code:

import logging, sys

# set up logging to file - see previous section for more details
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s
%(message)s',
                    stream=sys.stderr)

# define a Handler which writes INFO messages or higher to the
sys.stderr
console = logging.StreamHandler(sys.stdout)
console.setLevel(logging.INFO)
# set a format which is simpler for console use
formatter = logging.Formatter('%(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
#logging.getLogger('').addHandler(console)
logging.RootLogger(console)#.addHandler(console)

# Now, we can log to the root logger, or any other logger. First the
root...
logging.info('Jackdaws love my big sphinx of quartz.')
logging.debug('Ritesh raj Sarraf.\n')


With this it seems to be working halfway.
logging.debug() works perfect. But logging.info() is inheriting the
settings of logging.debug(). For example it is using logging.debug()'s
formatter while displaying. :-(

Ritesh




More information about the Python-list mailing list