简体   繁体   English

使用 log4j 登录 Java Web Start

[英]Logging in Java Web Start using log4j

I am migrating my application to Java Web Start.我正在将我的应用程序迁移到 Java Web Start。 I have a situation that my application logs the message using log4j and configuration file create the logs in the installation directory.我有一种情况,我的应用程序使用 log4j 记录消息,配置文件在安装目录中创建日志。

I am not sure how to create and store the logs while using Java Web Start.我不确定在使用 Java Web Start 时如何创建和存储日志。 Could any one tell me how to specify the file location for log4j?谁能告诉我如何为 log4j 指定文件位置?

You can pass the option to the JVM when it starts.您可以在 JVM 启动时将该选项传递给它。 On windows, this would look like:在 Windows 上,这看起来像:

-Dlog4j.configuration=file:/C:/MyApp/bin/log4j.properties

我们可以在 log4j.property 文件中添加以下条目

log4j.appender.F.File=${user.home}/quest.log 

While using log4j to log in your JWS application, your jnlp should contain reference to log4j library like this使用 log4j 登录您的 JWS 应用程序时,您的 jnlp 应包含对 log4j 库的引用,如下所示

<resources>
    <jar href="log4j-1.2.16.jar"/>
</resources> 

The log4j jar file should be in the same directory as of your JWS application jar file. log4j jar 文件应与 JWS 应用程序 jar 文件位于同一目录中。

Where to Log : Most preferred location to log is inside user home as the user has all rights there to create and modify files.在哪里登录:最喜欢的登录位置是在用户家中,因为用户在那里拥有创建和修改文件的所有权限。 log4j.appender.F.File=${user.home}/test.log log4j.appender.F.File=${user.home}/test.log

You may also like to use log4j socket appender, which sends the logging output to remote server.您可能还喜欢使用 log4j 套接字附加程序,它将日志输出发送到远程服务器。

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

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