[Python-ideas] Automagically set logger name
Tin Tvrtković
tinchester at gmail.com
Tue Dec 10 19:29:57 CET 2013
More information about the Python-ideas mailing list
Tue Dec 10 19:29:57 CET 2013
- Previous message: [Python-ideas] Pipe indentation
- Next message: [Python-ideas] Slightly changing the signature of the inspect.Parameter constructor
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello, usually logger instances are retrieved and initialized with the module name, using the well-known pattern: logger = logging.getLogger(__name__) In Java's very popular log4j library (which is cited as an influence by PEP 282), loggers are usually retrieved and initialized in basically an identical way: private final static Logger LOG = Logger.getLogger(<name-of-class>.class); However, in the upcoming log4j 2 library, a new way is available: private final static Logger LOG = LogManager.getLogger(); // Returns a Logger with the name of the calling class. [1] Basically the method throws an exception, catches it and fishes out the class name from the stack trace. This is a little less explicit, but still a more convenient (and less annoying) way of accomplishing an extremely common pattern. I was wondering what the core devs make of it: - is it a good idea? (In general, and in Python) Is it worth it? - is it feasible in Python? (taking into account other implementations too) - are there any gotchas that would make it worse than the current standard? [1]: https://svn.apache.org/repos/asf/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131210/e9476bca/attachment.html>
- Previous message: [Python-ideas] Pipe indentation
- Next message: [Python-ideas] Slightly changing the signature of the inspect.Parameter constructor
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list