简体   繁体   English

在Java GoogleAppEngine开发服务器上显示日志消息(与GWT一起使用)

[英]Making log messages visible on Java GoogleAppEngine development server (used with GWT)

I am using java.util.logging.Logger to do my logging on my Java GoogleAppEngine app. 我正在使用java.util.logging.Logger来登录我的Java GoogleAppEngine应用程序。 This works peachily when the app is deployed. 部署应用程序时,这很有效。 However, I am unable to see my log messages when running my app in the development server. 但是,在开发服务器中运行我的应用程序时,我无法看到我的日志消息。

Salient additional details: 突出的附加细节:

  • I'm running the app engine development server inside the GWT development mode container, not standalone. 我在GWT开发模式容器中运行app引擎开发服务器,而不是独立的。
  • I have a logging.properties configured, though it seems to make no difference (it works correctly in production with or without the logging.properties, and it does not work in development with or without the logging.properties). 我已经配置了logging.properties,虽然它似乎没有任何区别(它在生产中正常工作,有或没有logging.properties,并且它在使用或不使用logging.properties的开发中不起作用)。
  • If I use System.out.println on the development server, this is output to the terminal from which I ran the GWT development mode container. 如果我在开发服务器上使用System.out.println,则将其输出到运行GWT开发模式容器的终端。 Obviously this is a usable workaround, but I would like logging to just work in both development and production mode. 显然这是一个可用的解决方法,但我希望登录只能在开发和生产模式下工作。

Has anyone gotten logging working in development mode (with or without using AppEngine in conjunction with the GWT development mode container)? 是否有人在开发模式下进行日志记录(有或没有将AppEngine与GWT开发模式容器一起使用)? Is there some magic incantation I need to see my logging output? 我需要看一些神奇的咒语来查看我的日志输出吗?

I had the same problem yesterday, but now it works for me. 我昨天遇到了同样的问题,但现在它对我有用。

Not sure what the change was, but I will post my configuration below so you can try it out (running GAE 1.3.8, no GWT but shouldnt matter). 不知道改变是什么,但我会在下面发布我的配置,你可以尝试一下(运行GAE 1.3.8,没有GWT但不重要)。

Please note that the logs will appear in the console window (amongst the other server logging). 请注意,日志将显示在控制台窗口中(在其他服务器日志记录中)。 I am not sure you can get it to log to files since the server is running in some kind of sandbox. 由于服务器在某种沙箱中运行,我不确定您是否可以将其记录到文件中。 I have only tested this configuration in my local environment, not uploaded. 我只在本地环境中测试了此配置,而不是上传。

WEB-INF/appengine-web.xml: WEB-INF / AppEngine上-web.xml中:

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

WEB-INF/logging.properties: WEB-INF / logging.properties:

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

logtest.jsp: logtest.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import=" java.util.logging.Logger"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="sv" xml:lang="sv">
<head>
</head>

<%
Logger logger = Logger.getLogger("org.whatever.Logtest");
logger.info("logtest info");
logger.warning("logtest warning");
logger.severe("logtest severe");


%>

<body>
Check the console for logging
</body>

</html>

Plase change your WEB-INF/logging.properties file. Plase更改您的WEB-INF / logging.properties文件。

Add

    .level=INFO

Make sure you have the right log classes and logging level set up in your logging.properties file: 确保在logging.properties文件中设置了正确的日志类和日志记录级别:

WEB-INF/logging.properties: WEB-INF / logging.properties:

# Configure a file log for devserver
handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler
java.util.logging.FileHandler.pattern=/tmp/appengine-devserver.log
java.util.logging.FileHandler.limit=0  # no limit
java.util.logging.FileHandler.count=1
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM