[Python-Dev] Re: PEP 282 comments

Jim Fulton jim@zope.com
Mon, 25 Mar 2002 12:22:03 -0500


Trent Mick wrote:
> 
> So the decision is between the simpler:
> 
>     class Logger:
>         def info(self, msg, *args): ...
> 
>         def exception(self, msg, *args):
>             """Log sys.exc_info() at the ERROR level"""
> 
> and the slightly more complex:
> 
>     class Logger:
>         def info(self, msg, *args, **kwargs):
>             """Use kwargs["exc_info"] to log an exception at this level."""
> 
>         def exception(self, msg, *args, **kwargs):
>             """Optionally pass in kwargs["exc_info"] otherwise sys.exc_info()
>             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 exc_info, that may differ from
>         sys.exc_info().
> 
> 
> 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 exc_info other than sys.exc_info() 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