Unable to view my own logs in Google App Engine

I am trying to do some simple registration with GAE, although I think I should skip some simple step.

I followed the instructions below: https://developers.google.com/appengine/docs/java/runtime#Logging

I want to write a simple log message, for example:

public class InsertServlet extends HttpServlet { private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(InsertServlet.class.getName()); public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { log.info("Handled GET request - custom message"); resp.setContentType("text/plain"); resp.getWriter().println("HELLO"); } } 

If I am in my application with a web browser, I see that it works (get the “HELLO” message in the browser).

However, after that, if I visit the logs in the console, I see that it is logging an event, but I do not see my message anywhere.

I selected "Show: all queries", but that’s all I see in the logs after my visit:

012-08-19 13: 34: 56.488 / insert 200 2922ms 0kb Mozilla / 5.0 (Windows NT 6.1; WOW64; rv: 14.0) Gecko / 20100101 Firefox / 14.0.1

2602: 306: ce97: de40: 8dbd: ace7: 14c3: 89e2 - - [19 / Aug / 2012: 13: 34: 56 -0700] "GET / insert HTTP / 1.1" 200 52 - "Mozilla / 5.0 (Windows NT 6.1, WOW64; rv: 14.0) Gecko / 20100101 Firefox / 14.0.1 "msgstr" msgid. Msgstr "" msgid. " msgid. msgstr "cpm_usd = 0.000006 loading_request = 1 Instance = 00c61b117cf339fa358dc217b91a9f45b8c30f

I 2012-08-19 13: 34: 56.487

This request caused a new process for your application, and thus, your downloadable application code was downloaded for the first time. Thus, this request may take longer and use more CPU than the typical request for your application.

Logging.Properties (only one line):

 .level = WARNING 

AppEngine-web.xml

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

Where is my user line log.info ? I do not look in the right place?

+6
source share
2 answers

First, I would say that using this setting in the logging.properties file:

 .level = WARNING 

And you ( do not specify any level when entering your code, the default level will be used, which, of course, is not a "WARNING" (I would suggest INFO ^^) do specify the level of logging using this line:

 log.info(msg); /* which is same as */ log.log(Level.INFO, msg); 

So the result is that you only register at the "INFO" level (in your example), but your configuration file says to register at WARNING and above. Because the “information” level is below the “warning”, they are discarded from your log file and not displayed in your server’s log.

I suggest trying this method instead, which forces you to specify the level of logging.

 import java.util.logging.Level; import java.util.logging.Logger; /* ... */ log.log(Level.INFO, "a info msg"); //info log.log(Level.WARNING, "a warning msg"); //warning log.log(Level.FINEST, "a fine(st) msg"); //debug (as finest) 

After that, you can use the logging.properties file to set the logging levels that you want for the classes you need:

 # Set the default logging level for all loggers to WARNING .level = WARNING # Set level for your app oed.server.level = INFO oed.server.data.datastore.myInjector.level = FINEST 

Edit2: This registration configuration does not affect client-side operation. When you want to register a message in GWT, there is this GWT.log(message); but no level can be specified.

This is not entirely correct, it depends on the configuration in your-app.gwt.xml . All details can be found in google dev guilde logging . I found this very useful and well done. However, in the walnut shell in GWT there are different default loggers (about 5-6); they are all configured in *.gwt.xml through their handlers (or can be done pragmatically). After you had an invasive pop-up registrar, I decided to remotely register it from server to server in order to use logging.properties , here is the configuration when using gwt.xml :

 <!-- Logging configuration --> <inherits name="com.google.gwt.logging.Logging"/> <set-property name="gwt.logging.logLevel" value="INFO"/> <!-- # To change the default logLevel --> <set-property name="gwt.logging.enabled" value="TRUE"/> <set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" /> <!-- Remote logging (linked with servlet) --> <set-property name="gwt.logging.popupHandler" value="DISABLED" /> <set-property name="gwt.logging.developmentModeHandler" value="ENABLED" /> <set-property name="gwt.logging.systemHandler" value="ENABLED" /> <set-property name="gwt.logging.firebugHandler" value="DISABLED" /> <set-property name="gwt.logging.consoleHandler" value="ENABLED"/> 

If you use this setting, be sure to configure web.xml using the servlet definition for logging (this is not indicated in the documentation, unfortunately):

 <servlet> <servlet-name>remoteLogging</servlet-name> <servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl</servlet-class> </servlet> <servlet-mapping> <servlet-name>remoteLogging</servlet-name> <url-pattern>/your-app-name/remote_logging</url-pattern> </servlet-mapping> 

Good luck

+9
source

Instead of checking “All queries”, you should check “Logs with minimal severity” and select “Information” from the drop-down list.

0
source

Source: https://habr.com/ru/post/923244/


All Articles