[Python-Dev] Re: PEP 282 comments (original) (raw)
Jim Fulton jim@zope.com
Mon, 25 Mar 2002 12:22:03 -0500
- Previous message: [Python-Dev] Re: PEP 282 comments
- Next message: [Python-Dev] Re: PEP 282 comments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Trent Mick wrote:
So the decision is between the simpler: class Logger: def info(self, msg, *args): ... def exception(self, msg, *args): """Log sys.excinfo() at the ERROR level""" and the slightly more complex: class Logger: def info(self, msg, *args, **kwargs): """Use kwargs["excinfo"] to log an exception at this level.""" def exception(self, msg, *args, **kwargs): """Optionally pass in kwargs["excinfo"] otherwise sys.excinfo() is called to log exception information at the ERROR level.""" The argument for the latter is that is adds the capability of: (1) Logging an exception at a level other than ERROR (for which Jeremy maintains there is a string use case and for which Kevin Butler gives a simpler use case); and (2) Optionally explicitly passing in excinfo, that may differ from sys.excinfo().
The argument for the former is: (1) KISS and YAGNI
It can't be YAGNI if there is a need.
(2) You should just be able to subclass Logger and add the functionality you want. This is only a string point if the given use cases are not at all common. (3) If you want to pass in excinfo other than sys.excinfo() then format it yourself or subclass Logger.
Thoughts?
We have a need to make it easy to include error traceback in logs regardless of the level.
Here are a couple of other alternatives:
C. Make arguments more explicit:
class Logger:
def info(self, msg, args=None, kwargs=None, exc_info=None):
def exception(self, msg, args=None, kwargs=None, exc_info=None):
I have to say that I don't like the trend toward use of *args and **kwargs
to pass arguments that will be just grabbed and passed to something else.
It provides only slight syntactic sure (especially for positional arguments)
and adds complications, like making it hard to add arguments to the function.
D. Provide an exception formatter that delays formatting until a message is logged. I don't like this so much because I'd prefer that the decision about whether to show a tracebeck be a policy of the back end.
Jim
--
Jim Fulton mailto:jim@zope.com Python Powered!
CTO (888) 344-4332 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
- Previous message: [Python-Dev] Re: PEP 282 comments
- Next message: [Python-Dev] Re: PEP 282 comments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]