This often happens after replacing `print` with `logging`
4. Using `logging.getLogger(__file__)` instead of `logging.getLogger(__name__)`
5. Sharing a logger across multiple files
E.g.
foo.py
LOGGER = logging.getLogger(name)
bar.py
from foo import LOGGER
6. Unnecessary calculations of logging arguments
Bad
logger.debug('Message with %s', expensive_func())
Good
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Message with %s', expensive_func())
Docs: https://docs.python.org/3/howto/logging.html#optimization
7. Not using built-in string formatting features
print
instead ofloging
logging.info
orlogging.getLogger()
instead oflogging.getLogger(__name__)
if name == 'main': main()
foo.py
LOGGER = logging.getLogger(name)
bar.py
from foo import LOGGER
Bad
logger.debug('Message with %s', expensive_func())
Good
if logger.isEnabledFor(logging.DEBUG): logger.debug('Message with %s', expensive_func())
Bad
logger.info('Some data: %s', repr(data))
Good
logger.info('Some data: %r', data)