我应该如何处理自定义 Log4j 附加程序依赖项

发布于 2024-08-13 05:58:48 字数 1060 浏览 3 评论 0原文

我编写了一个自定义 log4j 附加程序,它为每个日志条目创建一个新的 Solr 文档,但我在将其部署到 JBoss 时遇到问题。

源代码可以在 github 上查看,但真正的问题是尝试使用 JBoss 的附加程序。

jboss-log4j.xml 的相关部分如下所示:

<appender name="SOLR" class="com.stuartgrimshaw.solrIndexAppender.SolrIndexAppender" />

<root>
   <priority value="${jboss.server.log.threshold}"/>
   <appender-ref ref="CONSOLE"/>
   <appender-ref ref="FILE"/>
   <appender-ref ref="SOLR"/>
</root>

Solr 的依赖项都可以在提供的 .war 文件中找到,但我猜测当追加程序在启动过程中很早就初始化时,该应用程序还没有尚未部署,这就是为什么我在日志中看到此错误:

2009-11-29 10:40:57,715 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to Create: name=jboss.system:service=Logging,type=Log4jService state=Configured mode=Manual requiredState=Create
java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/SolrServerException

有什么方法可以延迟初始化直到部署 solr 应用程序,或者有没有办法部署 Solr 应用程序,以便它的库对jboss 启动时?

I've written a custom log4j appender that creates a new Solr document for each log entry and I'm having problems deploying it to JBoss.

The source is viewable on github but the real problem is trying to use the appender from JBoss.

The relevent bits of jboss-log4j.xml look like this:

<appender name="SOLR" class="com.stuartgrimshaw.solrIndexAppender.SolrIndexAppender" />

<root>
   <priority value="${jboss.server.log.threshold}"/>
   <appender-ref ref="CONSOLE"/>
   <appender-ref ref="FILE"/>
   <appender-ref ref="SOLR"/>
</root>

The dependencies for Solr are all available in the .war file that's supplied, but I'm guessing that when the appender is initialised quite early on in the boot process, that application hasn't been deployed yet, which is why I see this error in the log:

2009-11-29 10:40:57,715 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to Create: name=jboss.system:service=Logging,type=Log4jService state=Configured mode=Manual requiredState=Create
java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/SolrServerException

Is there any way I can delay the initialization till the solr app has been deployed, or is there a way to deploy the Solr app so it's libraries are visible to jboss while it boots?

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

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

发布评论

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

评论(3

您的好友蓝忘机已上羡 2024-08-20 05:58:48

我认为您可以将 Solr 库部署在 server/[jboss-configuration]/lib 中(也就是说,在 JBoss 4 中,在较新的版本中可能是相同的),然后它们在启动时可用。

或者不要使用 JBoss log4j 配置并在 WAR 中定义您自己的 log4j.xml(在 lib 中的 JAR 中或在类中)。部署时它将由应用程序类加载器加载。

I think you could either deploy the Solr libs in server/[jboss-configuration]/lib (in JBoss 4 that is, might be the same in newer versions), then they are available at boot time.

Or don't use the JBoss log4j configuration and define your own log4j.xml in your WAR (either in a JAR in lib or in classes). It will be loaded by the application classloader when it is deployed.

枕头说它不想醒 2024-08-20 05:58:48

正如您所发现的,您必须将 JAR 放入 JBoss 配置的 lib 目录中才能在 jboss-log4j.xml 中引用其类型,但是这个通常不是一个好的做法。

一个非常简单的替代方案是从应用程序内部以编程方式调用 log4j API。如果您有 WAR,则定义一个 ServetContextListener (或类似的东西),它在 WAR 部署时被调用,并附加您的附加程序。同样,当取消部署时,它会分离附加程序。

请参阅上一个问题的答案,了解如何开始执行此操作。

As you've discovered, you'd have to put your JAR into the JBoss config's lib directory in order to refer to its types in jboss-log4j.xml, but this is generally not good practise.

A pretty straightward alternative is to invoke the log4j API programmatically from inside your application. If you have a WAR, then define a ServetContextListener (or something similar) which is invoked when the WAR deploys, and which attaches your appender. Similarly, when undeployed, it detaches the appender.

See the answer to this previous question for how to get started doing this.

宣告ˉ结束 2024-08-20 05:58:48

我猜这是为了管理您的日志文件并使它们更易于搜索,就像 Splunk 那样???然而,这感觉像是一种相当奇怪的做法……有点“看,我可以让狗用后腿走路”之类的事情……很酷,但你为什么要这么做呢?

我认为一个更简单、更强大的方法是 a) 获取 Splunk 免费版! b) 有一个单独的进程,它使用磁盘上的日志文件并使用 Solr4J 将它们发送到 Solr。

我认为仅仅需要 Solr 来进行日志记录就增加了巨大的复杂性。

I am guessing that this is to manage your log files and make them easier to search, a la Splunk???? However, this feels like a fairly odd way of doing this.. kind of the "look, I can make a dog walk on it's hind legs" kind of thing... Cool, but why would you want to?

I think a much simpler, more robust approach is to a) grab Splunk Free Edition! b) have a seperate process that consumes your log files from disk and send them to Solr using Solr4J.

I think requiring Solr, just to do logging adds a huge level of complexity.

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