Opened 15 years ago
Closed 15 years ago
#14616 closed (wontfix)
Recommend a leading underscore on module-level loggers in docs
| Reported by: | dgolden_ichec | Owned by: | nobody |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The in-development django logging docs, at least at time of writing, suggest using "logger" for module-level logger instances. That is problematic - consider people doing "from blah import *" and accidentally grabbing the "wrong" logger instance. Using a leading underscore on such module-level loggers is therefore common in pythonland i.e.
_log = logging.getLogger(__name__)
While this is ultimately just a python quirk, I suggest the docs should be trivially amended to recommend a leading underscore (e.g. "_log") convention rather than "logger", possibly with a very brief explanation as to why, for beginner-friendliness. Mistakenly importing another module's logger leads to quite confusing logging behaviour.
I don't deny that
_logis a common idiom, but the real fix here is "don't usefrom blah import *", or, in a refined form "don't usefrom blah import *unless the module author has used__all__or has explicitly marked a module as safe forimport *". This transcends anything in the logging code -- it's just good advice in general.However, I'm going to mark this wontfix. There is a limit to how many times we can say "no, really, you need to learn Python" in Django's docs before Django's docs become a Python tutorial, and that's not what our docs are for.