strange behavious of the logging module?

Vinay Sajip vinay_sajip at yahoo.co.uk
Mon Sep 24 10:10:51 EDT 2007


On Sep 24, 8:03 am, Peter Otten <__pete... at web.de> wrote:
>
> It would still be a good idea to file a bug report.

Not sure where the bug is. The script below, when called, prints
"Information" to the console and "INFO     some_func Information" to
mc_rigid.log, as I would expect. (Python 2.5.1)

Best regards,

Vinay

import logging
logging.basicConfig(level=logging.DEBUG,
                    format='%(levelname)-8s %(funcName)-8s %
(message)s',
                    filename='mc_rigid.log',
                    filemode='w')
# define a Handler which writes INFO messages or higher to the
sys.stderr
console = logging.StreamHandler()
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)

def some_func():
    logging.info("Information")

if __name__ == "__main__":
    some_func()





More information about the Python-list mailing list