Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

given you’ve configured logging somewhere early on in the bootstrap phase of your app - there’s really few reason to go up and above having more than these two lines in all your logging modules

  import logging
  logger = logging.getLogger(__name__)
But boy oh have I seen some funny business where people attach the logger to their objects like so

   class Wat:
     def __init__(self):
       self.logger = logging.getLogger(…)
All for what? For WAT?!


That is a super common mistake from beginner python programmers.


To inherit the logger attribute in subclasses?? Save an import?


I mean, yes, what you said isn’t wrong, that is what you get but a: logging is effectively a global singleton object already b: other than less pasta, are there any benefits to saving a logger import? In the case of logging it would seem you would lose all the benefits of “__name__” that are mentioned in the article (which to reiterate are considered best practice)




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: