-
Notifications
You must be signed in to change notification settings - Fork 253
Open
Description
- Using
printinstead ofloging - Using root logger by
logging.infoorlogging.getLogger()instead oflogging.getLogger(__name__) - Configuring a logger on import
E.g.
import logging
logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler(sys.stdout))
if __name__ == '__main__':
main()
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
- 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
# Bad
logger.info('Some data: %s', repr(data))
# Good
logger.info('Some data: %r', data)
CastixGitHub and tomschr
Metadata
Metadata
Assignees
Labels
No labels