Logging is pretty easy in the Java Google App Engine it uses java.util.logging.Logger class to write messages to the log. You can control the behavior of this class using a logging.properties file, and a system property set in the app's appengine-web.xml file
Using eclipse IDE it will create the file logging.properties in WEB-INF folder and set system property in appengine-web.xml while creating the web project
...
The default log level is WARNING, which suppresses INFO messages from the output. To change the log level for all classes in the HelloWorldApp package, edit the logging.properties file and add an entry for HelloWorldApp.level, as follows:
level = WARNING com.tutorials.HelloWorldAppServlet.level=INFO
The logs that have been generated by your application are viewable under that application in the Administration Console
Lets add couple of logging statements in our HelloWorldApp as shown below
package com.tutorials; import java.io.IOException; import javax.servlet.http.*; import java.util.logging.Logger; @SuppressWarnings("serial") public class HelloWorldAppServlet extends HttpServlet { private static final Logger log = Logger.getLogger(HelloWorldAppServlet.class.getName()); public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { log.info("The log for the info"); log.warning("The log for the warning"); log.severe("The log for severe"); resp.setContentType("text/plain"); resp.getWriter().println("Hello, world"); } }When we run the application in eclipse ,we will see the logs in console as shown below
Jun 18, 2009 12:07:45 PM com.tutorials.HelloWorldAppServlet doGet INFO: The log for the info Jun 18, 2009 12:07:45 PM com.tutorials.HelloWorldAppServlet doGet WARNING: The log for the warning Jun 18, 2009 12:07:45 PM com.tutorials.HelloWorldAppServlet doGet SEVERE: The log for severe
After deploying the project in the appengine ,Access the application once so the logs are generated
In order to see all of the logs generated by our application, sign in to your Administration Console at http://appengine.google.com/admin. In the left hand navigation column, click on the 'Logs', As shown below
No comments:
Post a Comment