4

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 running?

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.

Saxon Druce
  • 17,406
  • 5
  • 50
  • 71

3 Answers3

6

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.

Robert Kluin
  • 8,282
  • 25
  • 21
6

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.

Saxon Druce
  • 17,406
  • 5
  • 50
  • 71
2

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.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Guido van Rossum
  • 16,690
  • 3
  • 46
  • 49
  • Hi Guido, when checking stats I am generally checking the performance of a request I have just made, so I just go to the /_ah/stats/ URL and click one of the last few requests. I therefore don't use the stats links in the logs, and so adding an info log for every request just clutters up the logs. Sometimes I want to review all info-level logs, and if every request has logged a stats line, I can't see the other logs in amongst the noise. Thanks. – Saxon Druce Sep 01 '11 at 08:34
  • I basically would like to have appstats running on my development machine all the time, instead of having to go enable it and perform whatever action I want to track again. So 99% of the time the appstats logging is just random noise that distracts from my personal debugging/logging. – Nick Farina Oct 05 '12 at 21:55
  • If you really think these logging entries are too annoying you could just override or monkey-patch Recorder.save() to call _save() -- everything else it does is redundant. You could file a feature request in our tracker to make this logging optional -- but it's going to get a low priority. – Guido van Rossum Oct 07 '12 at 23:43