import os, sys, logging
logger = logging.getLogg er("my_app")
conerr = logging.StreamH andler(sys.stde rr)
conerr.setLevel (logging.DEBUG)
conerr_formatte r = logging.Formatt er('%(levelname )s %(message)s')
conerr.setForma tter(conerr_for matter)
console = logging.StreamH andler(sys.stdo ut)
console.setLeve l(logging.INFO)
console_formatt er = logging.Formatt er('%(message)s ')
console.setForm atter(console_f ormatter)
logger.addHandl er(conerr)
logger.addHandl er(console)
logger.info("Ri tesh 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\Work space\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
logger = logging.getLogg er("my_app")
conerr = logging.StreamH andler(sys.stde rr)
conerr.setLevel (logging.DEBUG)
conerr_formatte r = logging.Formatt er('%(levelname )s %(message)s')
conerr.setForma tter(conerr_for matter)
console = logging.StreamH andler(sys.stdo ut)
console.setLeve l(logging.INFO)
console_formatt er = logging.Formatt er('%(message)s ')
console.setForm atter(console_f ormatter)
logger.addHandl er(conerr)
logger.addHandl er(console)
logger.info("Ri tesh 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\Work space\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
Comment