How do I set up logging for Google App Engine Java?

Google App Engine Java uses java.util.logging to generate log messages. I want to change the log messages that are displayed in Developer Console - Monitoring - Logs . The idea is to add additional output, like the username, without manually putting it in each log message:

log.info("user action");

      

should result in a logging result like

user "testuser": user action

      

So I created my own Formatter:

public class TestFormatter extends Formatter {
    @Override
    public String format(LogRecord record) {
        // find out username..
        return "user " + username + ": " + record.getMessage();
    }
}

      

Setting this parameter as the formatting for the ConsoleHandler in the logging.properties file has no effect: java.util.logging.ConsoleHandler.formatter = com.example.guestbook.TestFormatter

When deploying to local machine and trying to add it programmatically like this:

Logger rootLogger = Logger.getLogger("");
Handler[] handlers = rootLogger.getHandlers();
log.info("Handler[] size: " + handlers.length);
for(Handler h : handlers) {
    log.info(h.toString());
    h.setFormatter(new TestFormatter());
}

      

I am getting 2 handlers, one ConsoleHandler

and one DevLogHandler

. But setting the formatting results in the logs no longer being displayed. In GAE, I get handler 0 instead.

When I try to connect Logger.getGlobal()

instead Logger.getLogger("")

, I get a 0 handler in the local instance and a security exception: no permission to change the global value in GAE. This exception is already being thrown when trying to get the list of handlers.

Now my question is, is there a way to change the developer console logs this way? If so, how?

+3


source to share


1 answer


As I said, I got in the past a google ticket that I opened for a similar question

I would refuse to interfere with the Loggers / Handlers internally with GAE.



Also, the global logger cannot be configured, you can try it with a custom name Logger

+1


source







All Articles