Custom logging function

Peter Otten __peter__ at web.de
Tue May 26 18:13:21 EDT 2020


zljubisic at gmail.com wrote:

> Is this OK?
> 
> import logging
> 
> LOG_LEVEL = logging.getLevelName('DEBUG')
> 
> logging.basicConfig(level=LOG_LEVEL,
>                     format='%(asctime)s %(levelname)s %(name)s
>                     %(funcName)-20s %(message)s', datefmt='%d.%m.%Y
>                     %H:%M:%S')
> 
> stderr = logging.StreamHandler()
> stderr.terminator = '\r\n'
> logging.getLogger('').addHandler(stderr)
> 
> logging.info('Main script started')

You create two stream handlers that both log to stderr -- one with 
basicConfig() and one explicitly in your code. That's probably not what you 
want.



More information about the Python-list mailing list