Configure logging in Google App Engine

Google App Engine for Java is using java.util.logging.Logger to perform the logging. In this tutorial, we show you how to do logging in GAE environment.

1. Logging Example

Example to define a logger in MovieController, and log the messages in different logging levels (info, warning and error)

import java.util.logging.Logger;
//...
 
@Controller
@RequestMapping("/movie")
public class MovieController {
 
private static final Logger log = Logger.getLogger(MovieController.class.getName());
 
@RequestMapping(value="/{name}", method = RequestMethod.GET)
public String getMovie(@PathVariable String name, ModelMap model) {
 
log.info("Information log message.");
 
log.warning("Warning log message.");
 
log.severe("Error log message.");
 
return "page";
 
}
 
}

2. Logging Example

Create a file, logging.properties, set the logging level, and put it in “$project/war/WEB-INF

File : $project/war/WEB-INF/logging.properties

# Set the default logging level for all loggers to WARNING
.level = WARNING

3. appengine-web.xml

Update appengine-web.xml, define system properties tag, and point logging to above “WEB-INF/logging.properties“.

File : $project/war/WEB-INF/appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>mkyong-springmvc</application>
<version>1</version>
 
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
 
</appengine-web-app>

4. Done

In GAE local development environment, all logged message will be display on console. In GAE production environment, you can access the logged messages in your application’s administrator page.

gae java logging gae java logging
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s