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: patch-diff.githubusercontent.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:049e44f2-2e11-28da-5560-eb2c86916bbc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 89C4:14207:57B4493:71744AB:69753325 |
| html-safe-nonce | e963b0cf84e8e28388d8a429c464d9efe641e57e935ebb943bba648fb5f04580 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OUM0OjE0MjA3OjU3QjQ0OTM6NzE3NDRBQjo2OTc1MzMyNSIsInZpc2l0b3JfaWQiOiI2MDE4NzEzMTM1OTUzMDMxOTczIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bac63638e66be595dbf4fd8f5f373d9d1433b5e613aa3d7a9760cfe1dcb0e12d |
| 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 | 4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f |
| 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 | 488b30e96dfd057fbbe44c6665ccbc030b729dde |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width