Title: Logging anti-patterns · Issue #129 · quantifiedcode/python-anti-patterns · GitHub
Open Graph Title: Logging anti-patterns · Issue #129 · quantifiedcode/python-anti-patterns
X Title: Logging anti-patterns · Issue #129 · quantifiedcode/python-anti-patterns
Description: Using print instead of loging Using root logger by logging.info or logging.getLogger() instead of logging.getLogger(__name__) Configuring a logger on import E.g. import logging logger = logging.getLogger(__name__) logger.addHandler(loggi...
Open Graph Description: Using print instead of loging Using root logger by logging.info or logging.getLogger() instead of logging.getLogger(__name__) Configuring a logger on import E.g. import logging logger = logging.get...
X Description: Using print instead of loging Using root logger by logging.info or logging.getLogger() instead of logging.getLogger(__name__) Configuring a logger on import E.g. import logging logger = logging.get...
Opengraph URL: https://github.com/quantifiedcode/python-anti-patterns/issues/129
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Logging anti-patterns","articleBody":"1. Using `print` instead of `loging`\r\n2. Using root logger by `logging.info` or `logging.getLogger()` instead of `logging.getLogger(__name__)`\r\n3. Configuring a logger on import\r\nE.g.\r\n```\r\nimport logging\r\nlogger = logging.getLogger(__name__)\r\nlogger.addHandler(logging.StreamHandler(sys.stdout))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n```\r\nThis often happens after replacing `print` with `logging`\r\n4. Using `logging.getLogger(__file__)` instead of `logging.getLogger(__name__)`\r\n5. Sharing a logger across multiple files\r\nE.g.\r\n```\r\n# foo.py\r\nLOGGER = logging.getLogger(__name__)\r\n\r\n# bar.py\r\nfrom foo import LOGGER\r\n```\r\n6. Unnecessary calculations of logging arguments\r\n```\r\n# Bad\r\nlogger.debug('Message with %s', expensive_func())\r\n\r\n# Good\r\nif logger.isEnabledFor(logging.DEBUG):\r\n logger.debug('Message with %s', expensive_func())\r\n```\r\nDocs: https://docs.python.org/3/howto/logging.html#optimization\r\n7. Not using built-in string formatting features\r\n```\r\n# Bad\r\nlogger.info('Some data: %s', repr(data))\r\n\r\n# Good\r\nlogger.info('Some data: %r', data)\r\n```","author":{"url":"https://github.com/amorgun","@type":"Person","name":"amorgun"},"datePublished":"2019-07-25T11:04:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/129/python-anti-patterns/issues/129"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:284a1dcc-c7d3-a579-b201-311a132800d4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D6AE:2EC266:21176BA:2D736F7:696ABBE5 |
| html-safe-nonce | e03a13fb544b0153def7a6ccee1af4684aeff624611ed05be9ff75dfbf8bc6b1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkFFOjJFQzI2NjoyMTE3NkJBOjJENzM2Rjc6Njk2QUJCRTUiLCJ2aXNpdG9yX2lkIjoiMjM5MDk0NDc4MTQ3NTQyOTM0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cbee80d97f5eb910cf1ce185c82f29131cb6f8bb29c064a63042de17c57420f9 |
| hovercard-subject-tag | issue:472802928 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/quantifiedcode/python-anti-patterns/129/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3f293ab3d86ba9850ca8790f24857c4d475731e0813d714e2dd49b7e2c70001d/quantifiedcode/python-anti-patterns/issues/129 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3f293ab3d86ba9850ca8790f24857c4d475731e0813d714e2dd49b7e2c70001d/quantifiedcode/python-anti-patterns/issues/129 |
| og:image:alt | Using print instead of loging Using root logger by logging.info or logging.getLogger() instead of logging.getLogger(__name__) Configuring a logger on import E.g. import logging logger = logging.get... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | amorgun |
| hostname | github.com |
| expected-hostname | github.com |
| None | 46ce962e0e18113ea447391b6ace8b02d4d2861e57b4fbab3658698f73d8855b |
| turbo-cache-control | no-preview |
| go-import | github.com/quantifiedcode/python-anti-patterns git https://github.com/quantifiedcode/python-anti-patterns.git |
| octolytics-dimension-user_id | 6774260 |
| octolytics-dimension-user_login | quantifiedcode |
| octolytics-dimension-repository_id | 22258112 |
| octolytics-dimension-repository_nwo | quantifiedcode/python-anti-patterns |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22258112 |
| octolytics-dimension-repository_network_root_nwo | quantifiedcode/python-anti-patterns |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 30300f30bb3949de255e84a146706a3bdb5c19c9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width