João Eiras <[email protected]> added the comment:
Hi.
I ask for this to be reconsidered. The "recommended" approach of using
"getLogger(__name__)" comes with some downsides.
In my projects I often have many many files (in one particularly I have
hundreds) and creating Logger object for each and every file, so LogRecord.name
is correct is burdensome, litters the code and forces to add a global variable
to the file. So, the easy approach we took was to use using logging.log(...)
everywhere.
I've also seen code elsewhere where it is not guaranteed that
"getLogger(__name__)" is called with the module __name__, but with some other
string.
Or I've seen code where there is a shared Logger() created in some config.py
that is then imported into other files.
Overall, relying on LogRecord.name is error prone and requires adding more code.
I checked the logging module. The findCaller() function could easily just poke
frame.f_globals.get("__name__") to get the module name, and propagate that to
the LogRecord.
It's a simple addition. I can make a PR so you can comment further there. The
name of the property would be LogRecord.fullModule.
Thank you.
----------
nosy: +João Eiras
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue29036>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com