Log4J和Java Web Start,如何在不同配置之间交替?
我从 Log4J 开始,希望在 Java Web Start 分布式应用程序中有一个默认的 log4j.properties,它仅记录错误和重要事件。
但是,如果某个客户端出现问题,我想要获得更详细的日志,则执行此操作的方法是在此客户端中定义备用 log4j 配置文件。这可以通过使用 log4j.configuration 系统属性指定备用配置文件来完成。
但是...我如何在 java web start 启动的应用程序中为这个特定客户端定义系统属性? (我知道我可以在 .jnlp 文件中定义这些属性,但这会影响所有客户端)。
我们的用户在 Windows 环境中工作,但他们通常拥有受限权限的计算机,并且无法访问“我的电脑”->“属性”-->“高级选项”-->“环境变量”(我使用的是西班牙配置的计算机,我不这样做)不知道确切的英文名称)。
i'm starting with Log4J and i want to have a default log4j.properties in our Java Web Start distributed application, which only logs errors and important events.
But if something was wrong in one client i want to have a more detailed log, the way to do this is to define an alternate log4j configuration file in this client. This can be done by specifiying the alternate config file with the log4j.configuration system property.
but... How can i define an system property for this particular client in a java web start launched application? (i know that i can define theese propeties in the .jnlp file, but this affects all clients).
Our users work in windows environment but they often have a restricted permissions computer and they can't acces My Pc->Properties-->Advanced Options-->Enviroment Variables (i'm in a spanish configured computer i don't know the exact names in english).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以访问客户端磁盘上定义的目录吗?
如果可以的话,您可以定义一个约定:如果在目录中找不到配置文件,则使用默认配置。否则,加载特定的配置文件。
您可以使用 PropertyConfigurator 类 来做到这一点Log4J 的:
Can you access to a defined directory on the client disk ?
If you can, you can define a convention : if no configuration file is found in the directory, the default config is used. Else, the specific configuration file is loaded.
You can do that with the PropertyConfigurator class of Log4J :
首先,如果您使用小程序,您应该使用一个可以写入远程位置的附加程序,这样您就可以实际看到错误,而无需实际位于小程序正在运行的本地计算机上。 附加器类型。接下来,您需要创建一个附加程序,其阈值是您记录正常“访问”类型消息的任何级别。将布局设置为您想要的任何内容。然后创建另一个附加程序,其级别至少为您记录“错误”的级别以及其自己的格式,以满足您“更详细”的需求。这样,当您的代码调用错误消息时,它将使用不同的布局。 Log4j 相当复杂,但并非无法理解。查看 log4j 站点 上的文档,并了解一些简单的日志记录。之后您应该能够修改代码以获得您想要的。
First off if you are using applets you should use an appender that can write to a remote location so you can actually see the errors without being physically on the local machine that the applet is running. Appender Types. Next, you need to create an appender with a threshold of whatever level you are logging the normal "access" type messages. Set the layout to whatever you desire. Then create another appender with a level of at least the level you log "errors" at as well as its own format that suits your needs as being "more detailed". That way when your code calls an error message it will use that different layout. Log4j is fairly complex but not impossible to understand. Look at the documentation at The log4j site and get your feet wet on some simple logging. After that you should be able to modify the code to get what you desire.