如何为Vaadin服务器和客户端配置Generell日志记录?

时间:2019-07-10 12:29:37

标签: java logging gwt vaadin vaadin8

我的Vaadin应用程序中有一些神秘的行为(我偶尔会得到一个白色的浏览器窗口)。因此,我通常希望为客户端和服务器端激活日志记录,以希望检测到一些有用的提示,这是什么问题。 为了激活客户端(GWT)的日志记录,我发现了类似的东西,必须将其放置在widgetset.gwt.xml中:

$(document).ready(function f() {
    $.ajax('http://soner.dev/test.txt', {
        success: function(data, status, xhr) {
            var parsedData = JSON.parse(data);
            $.each(parsedData, function( key, val ) {
                console.log(key + " : " + val);     
                alert(key + " : " + val);  
                $(`#${key}`).val(val);
            });
            setTimeout(f, 1000); // refresh the data at each second(data changes at each 1sec)
        }
    });
}); 

但是当我启动该应用程序并且应该记录一些内容时,我只能看到一条错误消息:

<inherits name="com.google.gwt.logging.Logging"/>
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
<set-property name="gwt.logging.logLevel" value="INFO"/> <!-- SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST -->
<set-property name="gwt.logging.enabled" value="TRUE"/>

对于服务器端日志记录,我发现:

com.vaadin.server.VaadinServlet          : Requested resource [/VAADIN/widgetsets/myApplication.vaadin.widgetset.MyApplicationWidgetset/remote_logging] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.

但是我必须放置在哪里?据我了解,Vaadin使用Java记录器。我正在使用log4j。但是应该可以使用Java记录器登录到log4j记录器,或者? 最后,我希望有一个在客户端和服务器端都有很多日志记录的应用程序进入我的log4j日志文件。

非常感谢

3 个答案:

答案 0 :(得分:0)

如果您更新module.gwt.xml,则还必须更新GWT编译器的类路径,以包括所用库的类JAR和源代码文件。

答案 1 :(得分:0)

我能够解决我的远程日志记录问题。我忘了添加一个新的Servlet,通过远程日志记录调用该Servlet,以将数据从客户端“传输”到服务器,例如:

@WebServlet(
        name = "remoteLogging",
        // The url from the error message according missing ressources
        urlPatterns = "/VAADIN/widgetsets/myApplication.vaadin.widgetset.MyApplicationWidgetset/remote_logging"
)
public class GwtRemoteLoggingServlet
extends com.google.gwt.logging.server.RemoteLoggingServiceImpl
{}

我不能使用调试控制台之类的东西,因为该问题仅发生在生产环境中。而且我不想向我们的客户解释如何使用Firefox开发工具...

感谢有关u2f的提示。我会看一下,但我不认为这是问题所在,因为它也会在Chrome等系统中发生。但是我们仍然使用的Vaadin版本会受到影响,所以...

有什么消息我会报告。

答案 2 :(得分:0)

我还能够激活Vaadin和Atmosphere服务器端的日志记录。首先,必须是 com.Vaadin com.vaadin 。我还要解决配置JUL的问题,因为我没有在其他地方使用JUL。我以一种快速而肮脏的方式做到了:

final String julConfiguration = String.join( " \n",
        "handlers = java.util.logging.FileHandler",
        "java.util.logging.FileHandler.limit = 99999999",
        "java.util.logging.FileHandler.count = 20",
        "java.util.logging.FileHandler.pattern = /<path>/java_util_logging_%u_%g.log",
        "com.vaadin.level = ALL",
        "org.atmosphere.level = ALL"
);

final BufferedInputStream inputStream = new BufferedInputStream(
        new ReaderInputStream( new StringReader( julConfiguration ) ) );
LogManager.getLogManager().readConfiguration( inputStream );