开发者

Cherrypy and duplicate error messages in apache logs

开发者 https://www.devze.com 2023-02-19 09:11 出处:网络
I have a simple cherrypy app that dynamically creates and serves PDF files. Inside the app, I am logging开发者_运维百科 some simple text to apache\'s error logfile.

I have a simple cherrypy app that dynamically creates and serves PDF files. Inside the app, I am logging开发者_运维百科 some simple text to apache's error logfile.

The logging is done via python's standard logging interface:

logging.debug('My log message')

The problem is, I notice that I am always seeing exactly 11 copies of each statement printed to the error log from within cherrypy.

e.g.:

[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION
[Thu Mar 24 18:44:46 2011] [error] USER AUTHORIZED BY SESSION

The app itself works, and returns the correct PDF file, but I am trying to figure out why it appears as though the webapp is called 11 times for each web request.

Does anyone have any idea where to start looking? I am guessing this is either an apache or cherrypy configuration issue? Could someone familiar with cherrypy help me out?

Any help greatly appreciated.


Looks like a common problem if you don't use cherrypy's logging functions. Basically, each thread will add its handler to the global logger, resulting in duplicate entries.

http://groups.google.com/group/cherrypy-users/browse_thread/thread/a74859627fea14e4


11 times sounds like once in the main thread and once for each of the 10 HTTP request threads. I wonder where you're calling logging.debug from.


Setting cherrypy.log.error_log.propagate = False didn't work for me, but adding a filter did wonders:

class FilterAll(logging.Filter):
    def filter(self, record):
        return False

cherrypy.log.error_log.handlers[1].addFilter(FilterAll())      # Filter out duplicate cherrypy messages

No more duplicates

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号