On 2018-08-13 12:37 PM, Keep Secret wrote: > #!/usr/bin/env python3 > import logging > logging.basicConfig(filename='example.log',level=logging.DEBUG) > logging.basicConfig(format='%(asctime)s;%(levelname)s:%(message)s', > level=logging.DEBUG) > logging.debug('Message1) > logging.info('Message2') > logging.warning('Message3') > > DEBUG:root:Message1 > INFO:root:Message2 > WARNING:root:Message3 > BUT if I remove > logging.basicConfig(filename='example.log',level=logging.DEBUG) > I get > 2018-08-13 18:35:48,982;DEBUG:Message1 > 2018-08-13 18:35:48,982;INFO:Message2 > 2018-08-13 18:35:48,983;WARNING:Message3 > > Can someone please tell me what I am doing wrong? > Thanks
The logging module doesn't allow you to update its config. You're supposed to configure all the options you want in a single call to basicConfig (or one of the other config methods for a different way to configure logging) >>> import logging >>> logging.basicConfig(filename='example.log',level=logging.DEBUG,format='%(asctime)s;%(levelname)s:%(message)s') >>> logging.info('Message2') >>> logging.warning('Message3') produces this 2018-08-13 12:52:03,330;INFO:Message2 2018-08-13 12:52:04,231;WARNING:Message3 Alex -- https://mail.python.org/mailman/listinfo/python-list