Python 3.6 Logging time is not listed

2018-08-13 Thread Keep Secret
#!/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


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.6 Logging time is not listed

2018-08-20 Thread Keep Secret
On Monday, 13 August 2018 19:42:57 UTC+2, Léo El Amri  wrote:
> On 13/08/2018 19:23, MRAB wrote:
> > Here you're configuring the logger, setting the name of the logfile and
> > the logging level, but not specifying the format, so it uses the default
> > format:
> > 
> >> logging.basicConfig(filename='example.log',level=logging.DEBUG)
> > 
> > Here you're configuring the logger again, this time specifying the
> > format and the logging level, but not a path of a logging file, so it'll
> > write to the console:
> > 
> >> logging.basicConfig(format='%(asctime)s;%(levelname)s:%(message)s',
> >> level=logging.DEBUG)
> > 
> > The second configuration is overriding the first.
> 
> No, the second is not overriding the first one. The second call simply
> does nothing at all. See
> https://docs.python.org/3/library/logging.html#logging.basicConfig :
> "This function does nothing if the root logger already has handlers
> configured for it."

That is a bit odd. I would have thought that multiple calls to

logging.basicConfig with different parameters would have been acceptable.

So something like
 logging.basicConfig (

filename='example.log',level=logging.DEBUG,

format='%(asctime)s;%(levelname)s:%(message)s',

level=logging.DEBUG)

)

would presumably be accepted?

-- 
https://mail.python.org/mailman/listinfo/python-list