Logging Levels

Wednesday 10 October 2012

Running Go on Google Appengine means I can use the appengine.Context logging functions to record important (or not-so important) information about the running of the site. But there are 5 different levels of logging, so which should I use for what? In order to be consistent I have come up with these rules for deciding which level to use:
  1. Debug
  2. Trivial information that should only be useful when actually debugging. Traces function calls and follows utterly routine code paths.
    c.Debugf("HTML for %s was in memcache", path)
  3. Info
  4. Normal operation of the site, roughly one message per successful page served. Since the usual expiry time is something like one minute, I expect most pages to be cached. So recreating a page is a somewhat rarer event, although still completely expected.
    c.Infof("HTML for %s was not in memcache", path)
  5. Warning
  6. Something suspicious or unwanted. For instance a malicious user trying unusual inputs or me (as an admin) trying to do something stupid (like give two articles the same URL). Also used if part of Google's service fails. Ordinary users should not be able to trigger warning-level messages via normal use of a browser, unless there is a capabilities issue.
    logoutURL, err := user.LogoutURL(c, "/")
    if err != nil {
        c.Warningf("Could not create logoutURL: %s", err) 
  7. Error
  8. A bug in the code. Something has happened that given my current knowledge of how the site works, could not happen. If I can't create a page from my templates, something has gone wrong!
    if err := t.ExecuteTemplate(&b, name+".tmpl", fields); err != nil {
        c.Errorf("Error creating %s from template: %s", name, err)
  9. Critical
  10. Disastrous or dangerous bug or security hole detected. Used immediately before shutting down (panicing) to prevent damage. Only used once so far, as a final check that only an Admin can edit articles.
    if !user.IsAdmin(c) {
        c.Criticalf("Unauthorised Access to edit by %s", user.Current(c))
    To restrict access to certain URLs you can add them to your app.yaml file:
    - url: /secret_url

Previous (Using a buffered channel as a counter in Go)
Next (Binary Search)