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

References

  1. java.util.logging.Logger
  2. GAE logging
Tags :
Founder of Mkyong.com, love Java and open source stuffs. Follow him on Twitter, or befriend him on Facebook or Google Plus.
Here are some of my recommended Books

Related Posts

Popular Posts