无法使用karaf 3.0.4进行logback [英] Unable to make logback work with karaf 3.0.4

查看:198
本文介绍了无法使用karaf 3.0.4进行logback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使karaf 3.0.4使用logback.在代码中,我尝试以编程方式为回退记录器创建FileAppender.

I am attempting to make karaf 3.0.4 use logback. In the code i attempt to programatically create a FileAppender for a logback logger.

ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("bingo");

这里LoggerFactor是SLF4J LoggerFactory.我尚未发布添加文件追加程序的代码.

Here the LoggerFactor is SLF4J LoggerFactory. I have not posted the code which adds the file appender.

这会在karaf中引发以下异常:

This throws the following exception in karaf:

Caused by: java.lang.ClassCastException: org.ops4j.pax.logging.slf4j.Slf4jLogger cannot be cast to ch.qos.logback.classic.Logger
at bingo.concurrent.TaskContextImpl.<init>(TaskContextImpl.java:34)
at bingo.concurrent.TaskExecutorImpl.execute(TaskExecutorImpl.java:83)

我已经解决了已经报告过的类似问题: 如何使Pax日志记录使用loggback配置

I have gone through the already reported similar questions: How to make Pax logging to use the loggback config

我已经做了以下事情:

  • 将pax-logging-logback做为startup.properties的一部分,因此它总是在karaf启动时安装.我使用的版本是1.8.3.
  • 更改的配置文件 org.ops4j.pax.logging.cfg org.ops4j.pax.logging.logback.config.file = $ {karaf.home}/etc/logback.xml
  • Made pax-logging-logback as part of the startup.properties so it always gets installed on karaf startup. The version that i have used is 1.8.3.
  • Changed configuration file org.ops4j.pax.logging.cfg org.ops4j.pax.logging.logback.config.file=${karaf.home}/etc/logback.xml

这没有帮助. karaf.log中没有捕获任何日志.我还尝试过手动安装pax-logging-logback,但这都没有帮助,并且我得到了相同的结果.

This did not help. There are no logs that gets captured in the karaf.log. I also tried manually installing pax-logging-logback but that did not help either and i has the same result.

我想念什么吗?

关于, 疯子

推荐答案

我设法解决了该问题.不幸的是,karaf捆绑了pax日志记录服务,该服务包装了自己的Slf4j记录器实现,并始终委托该实现.如果不仅希望将logback用作karaf日志的默认日志记录实现,而且希望在karaf上运行的应用程序代码中使用自定义的logback附加程序,则我们需要执行以下操作:

I have managed to resolve the issue. Unfortunately karaf comes bundled with pax logging service which wraps its own implementation for Slf4j logger and always delegates to that implementation. If one wishes to use logback as the default logging implementation not only for karaf logs but for defining custom logback appenders in the application code that runs on karaf then we need to do the following:

有两种方法可以使其工作-使用osgi引导委派或在etc/config.properties中将软件包显式添加到org.osgi.framework.system.packages.extra中.我们选择后者,因为karaf只是一个本地运行时环境,我们希望快速测试内容,并且我们不想更改启动委托,因为那样会需要更改导入/导出各个捆绑包中软件包的方式.不是karaf的高效运行时.

There are 2 ways to make it work - use osgi boot delegation or explicitly add packages to the org.osgi.framework.system.packages.extra in etc/config.properties. We went with the latter as karaf was simply a local runtime where we wished to quickly test stuff and we did not want to change the boot delegation as that would have required changing the way we import/export packages in the individual bundles which would have affected the productive runtime which was not karaf.

  • 以下捆绑包需要删除: pax-logging-service,lib/bin/karaf-client.jar
  • 在lib文件夹中添加以下捆绑软件(karaf运行时支持的某些版本) slf4j-api,logback-core,logback-classic,jul-to-slfj,jcl-over-slf4j,osgi-over-slf4j
  • 在etc/startup.properties中-删除对pax-logging-service和pax-logging-api的引用
  • 在etc/config.properties中将所需的软件包添加到org.osgi.framework.system.packages.extra,确保没有多余的空间,因为karaf抱怨
  • 创建一个logback.xml并将其添加到$ karaf.home或$ karaf.home/etc
  • 注释掉etc/org.ops4j.pax.logging.cfg中的所有内容
  • 在etc/system.properties中,添加logback.configurationFile ="logback.xml文件的路径"
  • Following bundles needs to be removed: pax-logging-service, lib/bin/karaf-client.jar
  • To the lib folder add the following bundles (select versions which are supported by your karaf runtime) slf4j-api, logback-core, logback-classic, jul-to-slfj, jcl-over-slf4j, osgi-over-slf4j
  • In etc/startup.properties - remove references to pax-logging-service and pax-logging-api
  • Add required packages in etc/config.properties to org.osgi.framework.system.packages.extra, make sure that there are no extra spaces as karaf complains
  • Create a logback.xml and add it to either the $karaf.home or $karaf.home/etc
  • Comment out everything in etc/org.ops4j.pax.logging.cfg
  • In etc/system.properties add logback.configurationFile="path to logback.xml file"

仅此而已!!我们无法使org.apache.karaf.log.core和org.apache.karaf.log.command正常工作,并且由于我们未使用任何karaf日志记录控制台命令,因此我们将其保持不变.

That is all!! We were not able to make org.apache.karaf.log.core and org.apache.karaf.log.command work and since we did not use any karaf logging console commands we left it as is.

干杯!! 疯子

这篇关于无法使用karaf 3.0.4进行logback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆