使用 Java Web Start 配置 log4j

发布于 2024-10-03 13:51:29 字数 364 浏览 0 评论 0原文

我们的 Java WebStart 应用程序不包含 log4j 配置文件;它只是设置一些硬编码的记录器和附加器。

我希望个人客户能够将 log4j.properties 文件放在某个地方,并在故障排除情况下设置自己的自定义日志记录。我可以将 log4j.properties 文件捆绑到应用程序的某个 jar 中,这样就可以进行配置,但每个客户端的配置都是相同的,而不是只影响我想要排除故障的客户端。另外,我无法即时更改设置。

有没有办法劫持 log4j 初始化过程 以使用 per - 客户端配置文件?

Our Java WebStart application does not include a log4j configuration file; 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. 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. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三岁铭 2024-10-10 13:51:29

这里的基本问题是 Java Web Start 严格限制对机器的访问。

如果您正在运行签名的应用程序并且用户允许您完全访问计算机,您应该能够执行此操作。如果没有,则无法使用默认机制的 log4j 来执行此操作。

您可能想要编写自己的配置器,它使用 Java WebStart API 从文件系统读取数据,然后将其提供给 log4j,但这需要一些努力。

The basic problem here, is that Java Web Start severely restricts the access to the machine.

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.

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.

你是暖光i 2024-10-10 13:51:29

您可以使用 PersistenceService 将 log4j 配置存储在本地用户的计算机上(无需签名即可工作),或者至少存储一个关于是否在 Web Start 应用程序启动时加载特殊配置的标志。

还有一个FileOpenService,最终用户可以使用它打开本地 log4j.xml 文件来动态重新配置日志记录工具。这样,用户就可以控制配置,并且可以控制何时何地应用它。

使用 FileOpenService 将流获取到 log4j 配置文件的应用程序代码可以使用 DOMConfigurator.configure(InputStream) 重新配置 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.

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. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文