python logging module problem

Ritesh Raj Sarraf riteshsarraf at gmail.com
Thu Jul 13 05:37:38 EDT 2006


import os, sys, logging

logger = logging.getLogger("my_app")

conerr = logging.StreamHandler(sys.stderr)
conerr.setLevel(logging.DEBUG)
conerr_formatter = logging.Formatter('%(levelname)s %(message)s')
conerr.setFormatter(conerr_formatter)

console = logging.StreamHandler(sys.stdout)
console.setLevel(logging.INFO)
console_formatter = logging.Formatter('%(message)s')
console.setFormatter(console_formatter)

logger.addHandler(conerr)
logger.addHandler(console)

logger.info("Ritesh Raj Sarraf.\n")
logger.warning("Ricky Raj Sarraf.\n")

Hi,

When I execute the above code, logger.info()'s messages don't get
displayed. And logger.warning()'s messages get displayed twice.

C:\Eclipse\Workspace\Python Fun>python log.py
WARNING Ricky Raj Sarraf.

Ricky Raj Sarraf.


Is there something I am doing wrong ?
I basically want to use Python's logging module for my entire program.
I want is something like logger.message() which would contain normal
program messages which shouldbe passed to stdout.

I also want to implement a logger.verbose() handler which would execute
when we enable verbose mode.

Am I doing it the correct way ? Or am I using the wrong tool ? Should
logging be used for it ?

TIA,
Ritesh




More information about the Python-list mailing list