2

我尝试使用带有 Gelf Appender 的 Apache Karaf 连接到 Log4J,但我只是得到 ClassNotFoundException。

我按照Karaf Docs部分“使用您自己的附加程序”的说明进行操作:

我添加了一个文件夹并从 Maven 存储库system/org/graylog2/gelfj/1.1.12/复制到该文件夹​​中。gelfj-1.1.12.jar我将此行添加到etc/startup.properties

org/graylog2/gelfj/1.1.12/org.graylog2.gelfj-1.1.12.jar=7
org/ops4j/pax/logging/pax-logging-api/1.7.0/pax-logging-api-1.7.0.jar=8

(第二行已经存在,我按照说明“将新的片段包添加到 pax-logging-service 包之前的列表中”。)

我也添加到文件etc/org.ops4j.pax.logging.cfg

# Root logger
log4j.rootLogger=INFO,out,graylog2,osgi:*
...
log4j.appender.graylog2=org.graylog2.log.GelfAppender
log4j.appender.graylog2.graylogHost=foo.bar.de
log4j.appender.graylog2.facility=myall
log4j.appender.graylog2.Threshold=INFO

如果我开始 karaf 我只会得到这个例外:

/opt/apache-karaf-2.3.11/bin/karaf server
karaf: JAVA_HOME not set; results may vary
log4j:ERROR Could not instantiate class [org.graylog2.log.GelfAppender].
java.lang.ClassNotFoundException: org.graylog2.log.GelfAppender not found by org.ops4j.pax.logging.pax-logging-service [4]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1460)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191)
    at org.apache.log4j.helpers.Loader.loadClass(Loader.java:198)
    at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:326)
    at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:123)
    at org.apache.log4j.PaxLoggingConfigurator.parseAppender(PaxLoggingConfigurator.java:97)
    at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
    at org.apache.log4j.PropertyConfigurator.parseCatsAndRenderers(PropertyConfigurator.java:639)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:504)
    at org.apache.log4j.PaxLoggingConfigurator.doConfigure(PaxLoggingConfigurator.java:72)
    at org.ops4j.pax.logging.service.internal.PaxLoggingServiceImpl.updated(PaxLoggingServiceImpl.java:214)
    at org.ops4j.pax.logging.service.internal.PaxLoggingServiceImpl$1ManagedPaxLoggingService.updated(PaxLoggingServiceImpl.java:362)
    at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:148)
    at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:81)
    at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1436)
    at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1392)
    at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:103)
    at java.lang.Thread.run(Thread.java:701)
log4j:ERROR Could not instantiate appender named "graylog2".

我也尝试了这个指令,结果相同。

感谢帮助。

4

1 回答 1

1

取自最新的 gelfj-1.1.12.jar,我可以说它已经是一个片段包,将附加到 pax-logging-service 包。快速安装并刷新 pax-logging-service 捆绑包会成功安装它。从上面添加配置会导致找不到主机失败。

因此,由于 gelf 捆绑包已经是片段捆绑包,因此只需通过以下方式安装它

install mvn:org.graylog2/gelfj/1.1.12

和一个

refresh 2

或者只是重新启动容器。

于 2015-09-19T20:40:26.610 回答