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


Groups > comp.lang.python > #20626 > unrolled thread

Re: HTTP logging

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2012-02-20 18:07 +0100
Last post2012-02-20 10:53 -0800
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#20626 — Re: HTTP logging

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2012-02-20 18:07 +0100
SubjectRe: HTTP logging
Message-ID<mailman.14.1329757672.3037.python-list@python.org>
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

[toc] | [next] | [standalone]


#20629

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2012-02-20 09:47 -0800
Message-ID<3fbdb48b-675d-4345-a28c-1778bcb68108@db5g2000vbb.googlegroups.com>
In reply to#20626
On Feb 20, 5:07 pm, Jean-Michel Pichavant <jeanmic...@sequans.com>
wrote:

> 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.

Actually, I think it's a mistake in the docs - when they were
reorganised a few months ago, the text referring to raiseExceptions
was moved to the tutorial:

http://docs.python.org/howto/logging.html#exceptions-raised-during-logging

I will reinstate it in the reference API docs, but the answer to
Jason's problem is to either subclass HTTPHandler and override
handleError to suppress the error, or set logging.raiseExceptions to
True (in which case all logging exceptions will be swallowed - not
necessarily what he wants).

Regards,

Vinay Sajip

[toc] | [prev] | [next] | [standalone]


#20632

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2012-02-20 10:53 -0800
Message-ID<87f28356-5582-49f2-8b85-39f0c3b86380@e27g2000vbu.googlegroups.com>
In reply to#20629
On Feb 20, 5:47 pm, Vinay Sajip <vinay_sa...@yahoo.co.uk> wrote:

> I will reinstate it in the reference API docs, but the answer to
> Jason's problem is to either subclass HTTPHandler and override
> handleError to suppress the error, or set logging.raiseExceptions to
> True (in which case all logging exceptions will be swallowed - not

Um, that should be *False*, not True.

Regards,

Vinay Sajip

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web