Python logging.info() not logging the message
Asked Answered
L

1

16
parser_logger = logging.getLogger("CSHEL_parserlogger");
#logging.basicConfig()
parser_logger.addHandler(RotatingFileHandler(
                            "logfile", mode='a', maxBytes=7340032, backupCount=4,
                            encoding=None, delay=False))

#d = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' }
parser_logger.info('Protocol problem: %s', 'connection reset')

This would create a file named logfile, but won't write anything into it. If I change the last line to

parser_logger.warning('Protocol problem: %s', 'connection reset')

it would log the message into the "logfile" properly.

I am sure it's a petty thing that I am missing, but I am not able to figure out what it is.

Lest answered 19/10, 2011 at 18:3 Comment(0)
D
24

You need to set the threshold level of the logger:

parser_logger.setLevel(logging.INFO)

When a logger is created, the level is set to NOTSET, and the root logger is created with level WARNING. See the documentation.

Dunc answered 19/10, 2011 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.