简体   繁体   English

使用Java Web Start进行log4j配置

[英]log4j configuration with Java Web Start

Our Java WebStart application does not include a log4j configuration file; 我们的Java WebStart应用程序不包含log4j配置文件; it simply sets up some hardcoded loggers and appenders. 它只是设置了一些硬编码的记录器和追加器。

I would like individual clients to be able to drop a log4j.properties file in somewhere and set up their own custom logging in troubleshooting situations. 我希望各个客户能够在某处删除log4j.properties文件,并在故障排除情况下设置自己的自定义日志记录。 I could bundle a log4j.properties file into one of the jars of our application somewhere and that would allow configuration, but then the configuration would be the same for each client instead of only affecting the client that I want to troubleshoot. 我可以将log4j.properties文件捆绑到我们应用程序的某个jar中,这将允许配置,但是每个客户端的配置都是相同的,而不是仅影响我要解决的客户端。 Plus, I wouldn't be able to change settings on the fly. 另外,我无法动态更改设置。

Is there a way I can hijack the log4j initialization procedure to use a per-client configuration file? 有没有办法可以劫持log4j初始化过程来使用每个客户端的配置文件?

The basic problem here, is that Java Web Start severely restricts the access to the machine. 这里的基本问题是Java Web Start严格限制了对计算机的访问。

You should be able to do this, if you are running a signed application AND the user allows you full access to the machine. 如果您正在运行已签名的应用程序,并且该用户允许您完全访问该计算机,则应该能够执行此操作。 If not, you cannot do this with log4j with the default mechanism. 如果没有,则无法使用默认机制log4j执行此操作。

You may want to write your own configurator which reads from the file system using the Java WebStart API an then feeds that to log4j, but it will require some elbow grease. 您可能希望编写自己的配置程序,使用Java WebStart API从文件系统读取,然后将其提供给log4j,但这需要一些肘部润滑剂。

You could use the PersistenceService to store the log4j configuration on the local user's machine (works without signing), or at least store a flag on whether to load a special config or not at startup of your web start application. 您可以使用PersistenceService将log4j配置存储在本地用户的计算机上(无需签名),或至少在启动Web启动应用程序时存储是否加载特殊配置的标志。

There is also a FileOpenService with which the end-user could open a local log4j.xml file to re-configure the logging facility on the fly. 还有一个FileOpenService ,最终用户可以使用该文件打开本地log4j.xml文件,以便即时重新配置日志记录工具。 That way, the user has the control over the configuration and he has the control when and where to apply it. 这样,用户可以控制配置,并且可以控制何时何地应用它。

Your app code which uses the FileOpenService to get the stream to the log4j configuration file can then use the DOMConfigurator.configure(InputStream) to reconfigure log4j. 您的应用程序代码使用FileOpenService获取到log4j配置文件的流,然后可以使用DOMConfigurator.configure(InputStream)重新配置log4j。

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

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