Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20626

Re: HTTP logging

Date 2012-02-20 18:07 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: HTTP logging
References <CANy1k1g1P-1hiC-=Ht5rLp2a6BvM=ZOk2NYL1e9u_BRcZCrSNA@mail.gmail.com> <CAJ6cK1Y3_oTSGPwgnEr6Hnhh22getcsLCZN_788XaujU3yDPiQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14.1329757672.3037.python-list@python.org> (permalink)

Show all headers | View raw


Arnaud Delobelle wrote:
> On 20 February 2012 16:03, Jason Friedman <jason@powerpull.net> wrote:
>   
>> I am logging to HTTP:
>>
>> logger.addHandler(logging.handlers.HTTPHandler(host, url))
>>
>> Works great, except if my HTTP server happens to be unavailable:
>>
>> socket.error: [Errno 111] Connection refused
>>
>> Other than wrapping all my logger.log() calls in try/except blocks, is
>> there a way to skip logging to the HTTPhandler if the HTTP server is
>> unavailable?
>>     
>
> Here's one: subclass HTTPHandler :)
>
>   
short answer:

use

 > logging.raiseExceptions = 0


long and incomplete answer:

log calls should not raise any exception.

http://docs.python.org/library/logging.html#handler-objects

"Handler.handleError(record)
This method should be called from handlers when an exception is 
encountered during an emit() call. By default it does nothing, which 
means that exceptions get silently ignored. This is what is mostly 
wanted for a logging system - most users will not care about errors in 
the logging system, they are more interested in application errors. You 
could, however, replace this with a custom handler if you wish. The 
specified record is the one which was being processed when the exception 
occurred"
"

However, I looked into the code and find out an (undocumented ?) 
attribute of the logging module : raiseException which value is set to 1 
by default (python 2.5.2 logging.__version__ < '0.5.0.2' > ).

When set to 1, handlerError print the traceback.

This has been probably fixed in recent version of the module since the 
handleError doc does not reference raiseException anymore.

JM

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: HTTP logging Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-02-20 18:07 +0100
  Re: HTTP logging Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2012-02-20 09:47 -0800
    Re: HTTP logging Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2012-02-20 10:53 -0800

csiph-web