------------------------------------------------------------------------------
To reply, visit https://hellosplat.com/s/beanbag/tickets/4523/
------------------------------------------------------------------------------

New update by kyz
For Beanbag, Inc. > Review Board > Ticket #4523


Reply:

    Okay, I've figured this out fully. Here's the situation.
    
    All the logging methods (`logging.debug`, `logging.info`, 
`logging.warning`, `logging.error`, `logging.exception`, `logging.critical`, 
and `logging.log`) go through a common method on the root logger, 
`logging.RootLogger._log` (which is really `logging.Logger._log`). They are 
supposed to pass their arguments and keyword arguments to this method, which 
then interprets them. This is what understands things like the `extra=` keyword 
argument.
    
    We wrap `_log` on the root logger in order to accept a `request=` argument, 
as a convenience. That turns into a `extra={'request': request}`. This has been 
working for years, hence my surprise at the recent bug reports. However, now it 
makes sense.
    
    In some versions of Python (2.6.x, 2.7.0 through 2.7.5, 3.0.x, and 3.1.x), 
`logging.exception()` had a bug where keyword arguments were not accepted. The 
rest of the logging methods supported them, but when `logging.exception()` was 
introduced, it was left off. This bug remained until Python 2.7.6 and 3.2.
    
    The reason this started cropping up now is that, as part of some cleanup 
code, we started changing functions like this:
    
    ```python
    logging.error('...',
                  request=request,
                  exc_info=True)
    ```
    
    to this:
    
    ```python
    logging.exception('...',
                      request=request)
    ```
    
    The two calls are identical, basically. The latter is a wrapper for the 
former. However, since `logging.exception()` was lacking support for keyword 
arguments, this was failing on older versions of Python. Most people these 
days, according to our stats, use newer versions of Python 2.7.x, which is why 
we haven't been completely bombarded with bug reports, and why this wasn't 
happening on any servers under our control. (Worth noting that Review Board 3.0 
will require a newer version of Python than 2.7.5).
    
    The solution, it turns out, is not as simple as moving to 
`extra={'request': request}`. That would be wonderful. However, once again, 
that requires keyword argument support in `logging.exception()`, which doesn't 
exist in these versions.
    
    The good news is that we can intelligently monkey-patch 
`logging.Logger.exception()` to support keyword arguments if we determine it's 
lacking. We can also patch `logging.exception()`, which will work for anyone 
that doesn't do `from logging import exception` (which won't be us, and is a 
terrible idea -- this has to do with how imports work in Python).
    
    This is what I'm working on now, and we should be able to ship this 
Wednesday.


Status:
    - NeedInfo
    + Confirmed

-- 
You received this message because you are subscribed to the Google Groups 
"reviewboard-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/reviewboard-issues.
For more options, visit https://groups.google.com/d/optout.

Reply via email to