Disable Appstats logging
I'm using Appstats as documented here:
http://code.google.com/appengine/docs/python/tools/appstats.html
It works fine, but every request now logs an info message like this:
Saved; key: appstats:039300, part: 65 bytes, full: 12926 bytes, overhead: 0.000 + 0.004; link: http://example.com/stats/details?time=1290733239309
Is there a way to disable the log messages, while leaving Appstats runni开发者_开发技巧ng?
Maybe I could just take my own copy of ext/appstats/recording.py and comment out the call to logging.info()? Or is there a better way?
Thanks.
You might want to take a look at the sample appstats config file. You could configure appstats to only run for a percentage of your requests; that should reduce the number of logging messages but you'll still have the information.
If you want to patch appstats, you should take a look at line 303 in /google/appengine/ext/appstats/recording.py
. If you're using webapp it should be very easy to simply monkey-patch appstats by replacing its save method with its _save method.
Also, submit a feature request and post a link to the groups. I think being able to disable the logging call is a valid request; they do tend to clutter the logs up a bit.
In case anyone else is interested, here's how I removed the logging using Robert's monkey-patch suggestion.
The standard approach to insert appstats is like this:
def webapp_add_wsgi_middleware(app):
from google.appengine.ext.appstats import recording
app = recording.appstats_wsgi_middleware(app)
return app
This is what I did instead:
def webapp_add_wsgi_middleware(app):
from google.appengine.ext.appstats import recording
def save(self):
try:
self._save()
except Exception:
pass
recording.Recorder.save = save
app = recording.appstats_wsgi_middleware(app)
return app
This retains the original save() function's "ignore all exceptions" behaviour, but removes all of the logging around it.
Appstats' author here. Why do you want to disable the logging? I'm not saying that you shouldn't -- just that I'm surprised you want to disable it since I don't understand your reason. If it's a reasonable use case we can probably just add a configuration flag to disable it.
精彩评论