joke2k / django-environ

Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.
https://django-environ.rtfd.org
MIT License
3.03k stars 315 forks source link

Logger object name is the filepath rather than the module name #51

Closed edmorley closed 8 years ago

edmorley commented 9 years ago

From https://docs.python.org/2/library/logging.html#logger-objects :

The name is potentially a period-separated hierarchical value, like foo.bar.baz (though it could also be just plain foo, for example). Loggers that are further down in the hierarchical list are children of loggers higher up in the list. For example, given a logger with a name of foo, loggers with names of foo.bar, foo.bar.baz, and foo.bam are all descendants of foo. The logger name hierarchy is analogous to the Python package hierarchy, and identical to it if you organise your loggers on a per-module basis using the recommended construction logging.getLogger(__name__). That’s because in a module, __name__ is the module’s name in the Python package namespace.

Whereas at the moment, the logger object is instantiated using:

logger = logging.getLogger(__file__)

When using logging_tree to inspect the available logging objects, this results in:

>>> import requests
>>> import environ
>>> import logging_tree
>>> logging_tree.printout()
<--""
   Level WARNING
   |
   o<--[/home/vagrant/venv/local/lib/python2]
   |   |
   |   o<--[/home/vagrant/venv/local/lib/python2.7/site-packages/environ/environ]
   |       |
   |       o<--"/home/vagrant/venv/local/lib/python2.7/site-packages/environ/environ.pyc"
   |           Level NOTSET so inherits level WARNING
   |
   o<--"requests"
       Level NOTSET so inherits level WARNING
       Handler <logging.NullHandler object at 0xb6ed5f6c>
       |
       o<--[requests.packages]
           |
           o<--"requests.packages.urllib3"
               Level NOTSET so inherits level WARNING
               Handler <logging.NullHandler object at 0xb6ed5f0c>
               |
               o<--"requests.packages.urllib3.connectionpool"
               |   Level NOTSET so inherits level WARNING
               |
               o<--"requests.packages.urllib3.poolmanager"
               |   Level NOTSET so inherits level WARNING
               |
               o<--[requests.packages.urllib3.util]
                   |
                   o<--"requests.packages.urllib3.util.retry"
                       Level NOTSET so inherits level WARNING
>>>

ie: The logger name is /home/vagrant/venv/local/lib/python2.7/site-packages/environ/environ.pyc rather than environ (and compare to what is shown for requests).

edmorley commented 9 years ago

After the PR, the output from logging_tree becomes:

>>> import environ
>>> import logging_tree
>>> logging_tree.printout()
<--""
   Level WARNING
   |
   o<--[environ]
       |
       o<--"environ.environ"
           Level NOTSET so inherits level WARNING
>>>