Main Tutorials

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

References

  1. java.util.logging.Logger
  2. GAE logging

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Martin
9 years ago

That’s no typo. It simply doesn’t work that way. It’s a copy paste from manual and seems untested.

William
11 years ago

You have “.level = WARNING” in logging.properties so why are you getting INFO level messages in your logs?

winzter143
11 years ago
Reply to  William

Thats simply typo error bro. maybe the deploy apps log info. 🙂