自动log4j配置和bundleresource

发布于 2024-12-10 18:58:16 字数 1399 浏览 2 评论 0原文

两个问题:

1)在许多 log4j 线程/论坛/等中,我看到定义 log4j.debug 的结果,其中包含前缀为“file:”的 log4j 配置文件引用,如下所示

: log4j:使用 URL [file:/data/app/conf/log4j.properties] 进行自动 log4j 配置。

在我正在更新的代码中(由现在在其他地方工作的另一位开发人员编写),我看到:

log4j:使用 URL [bundleresource://23/log4j.properties] 进行自动 log4j 配置

如上所示的“bundleresource”是什么/在哪里?我认为这是一个我无法识别的专用资源 Eclipse 插件。


2)这个问题源于一个更大的问题,即如果没有显式地将log4j配置文件插入到JVM的命令行参数中(例如,-Dlog4j.configuration),则无法加载它。我正在替换测试服务器上基于 Eclipse 插件的应用程序,该应用程序在启动脚本中没有指定此命令行参数,并且能够在 log4j 正确初始化的情况下正确启动。当我用源存储库中的最新版本替换此应用程序时,该应用程序无法找到 log4j 配置文件。关于为什么第一个应用程序可以启动并找到 log4j 配置文件而第二个(较新的)应用程序不能启动并找到 log4j 配置文件的任何想法?

任何帮助将不胜感激。

谢谢!



更新/编辑

定义了 log4j.debug 的应用程序的输出:

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@9fe666.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@9fe666 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@9fe666.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@9fe666 class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].

Two issues / questions:

1) In many of the log4j threads / forums / etc., I am seeing the results of defining the log4j.debug containing log4j configuration file references prefixed with "file:" as shown below:


log4j: Using URL [file:/data/app/conf/log4j.properties] for automatic log4j configuration.

In the code I am updating (authored by another developer now working someplace else), I am seeing:


log4j: Using URL [bundleresource://23/log4j.properties] for automatic log4j configuration

What/where is the "bundleresource" as shown above? I am thinking this is a dedicated resource Eclipse plug-in that I have been unable to identify.

2) This question stems from a larger issue of not being able to load a log4j configuration file without explicitly inserting it into the command line arguments of the JVM (e.g., -Dlog4j.configuration). I am replacing an Eclipse plugin-based application on a test server that does not have this command line argument specified in a start up script and is able to correctly fire up with log4j being initialized correctly. When I go to replace this application with the latest build from our source repository, the application fails to locate the log4j configuration file. Any thoughts on why the first application can start up and locate the log4j configuration file while the second (newer) application cannot?

Any help would be greatly appreciated.

Thanks!

Update / Edit

Output from the application with log4j.debug defined:

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@9fe666.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@9fe666 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@9fe666.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@9fe666 class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].

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

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

发布评论

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

评论(1

你げ笑在眉眼 2024-12-17 18:58:16

您可以通过首先加载属性,然后将其扔到 log4j 的属性配置器中来加载 Log4j 的属性文件:

Properties props = new Properties();
FileInputStream fis = new FileInputStream("mylog4j.properties");
props.load(fis);
fis.close();
PropertyConfigurator.configure(props);

bundleresource 似乎是特定于库的东西。我建议在源代码上使用 grep :

grep -irn ./ -e "bundleresource"

You can load a properties file for Log4j by first loading the properties, then tossing it into log4j's property configurator:

Properties props = new Properties();
FileInputStream fis = new FileInputStream("mylog4j.properties");
props.load(fis);
fis.close();
PropertyConfigurator.configure(props);

The bundleresource seems like a library specific thing. I recommend using grep on the sourcecode:

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