Tuesday, March 22, 2011

AppEngine logging level

I tried to change the logging level in my Google App Engine app to FINE to see what was happening in Sitebricks.  I edited the /WEB-INF/logging.properties file to read:

.level = INFO
com.google.sitebricks.level = FINE 
 But still only WARN messages were logged to the console.

Finally I realised that on the launcher dialogue panel for GWT I had to also set the level to DEBUG.  But when I did that the console was flooded with GWT compile messages.  This is due to a new bug in GAE's logging where it tries to use the same settings as GWT but gives you no control of the GWT part.

So I installed a simple logging handler to get around this:


Put this in app init
if (isDevelopment()) { Logger.getLogger("").addHandler(new WorkaroundHander()); }
public boolean isDevelopment() { return System.getProperty("com.google.appengine.runtime.environment").equals("Development"); }
private static class WorkaroundHander extends Handler { public WorkaroundHander() { setFormatter(new TextLogFormatter(false)); setLevel(Level.ALL); }
@Override public void publish(LogRecord record) { if (isLoggable(record)) { System.out.println(getFormatter().format(record)); } } 
@Override public void flush() { } @Override public void close() throws SecurityException { } }


Now I I happily see all the FINE messages that Sitebricks has for me.

No comments: