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");
Here the LoggerFactor is SLF4J LoggerFactory. I have not posted the code which adds the file appender.
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)
I have gone through the already reported similar questions: How to make Pax logging to use the loggback config
I have already done the following:
- 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
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.
Am i missing something?
Regards, Madhav
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:
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.
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.
Cheers!! Madhav