Enabling Log4J2 externally in Karaf doesn't let log:set log:get to work

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Enabling Log4J2 externally in Karaf doesn't let log:set log:get to work

ngpon
This post has NOT been accepted by the mailing list yet.
Hi,

I have setup karaf 4.1.1 and one of the things that I have associated with this version is using Log4J2. The way I have configured pax logging is by making a reference to a standalone log4j2.xml configuration in etc/org.ops4j.pax.logging.cfg as:

org.ops4j.pax.logging.log4j2.config.file=${karaf.etc}/log4j2.xml

What I notice that though with these changes, logging works as expected but when I run a karaf client shell, the log:set & log:get commands do not work, giving the following error:

karaf@root()> log:get

21:28:31,131 | ERROR | nsole user karaf | ShellUtil
| 42 - org.apache.karaf.shell.core - 4.1.1 | Exception caught while executing command java.lang.IllegalStateException: Unrecognized configuration at org.apache.karaf.log.core.internal.LogServiceImpl.getDelegate(LogServiceImpl.java:50) [36:org.apache.karaf.log.core:4.1.1] at org.apache.karaf.log.core.internal.LogServiceImpl.getLevel(LogServiceImpl.java:68) [36:org.apache.karaf.log.core:4.1.1] at org.apache.karaf.log.command.GetLogLevel.execute(GetLogLevel.java:49) [36:org.apache.karaf.log.core:4.1.1] at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:84) [42:org.apache.karaf.shell.core:4.1.1] at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:68) [42:org.apache.karaf.shell.core:4.1.1] at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:86) [42:org.apache.karaf.shell.core:4.1.1] at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:560) [42:org.apache.karaf.shell.core:4.1.1] at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:486) [42:org.apache.karaf.shell.core:4.1.1] at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:375) [42:org.apache.karaf.shell.core:4.1.1] at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:417) [42:org.apache.karaf.shell.core:4.1.1] at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229) [42:org.apache.karaf.shell.core:4.1.1] at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59) [42:org.apache.karaf.shell.core:4.1.1] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:?] at java.lang.Thread.run(Thread.java:748) [?:?] Error executing command: Unrecognized configuration
It seems to me that there is a bug in the code (org.apache.karaf.log.core.internal.LogServiceImpl):

private LogServiceInternal getDelegate(Dictionary<String, Object> config) {
    if (config.get("log4j.rootLogger") != null) {
        return new LogServiceLog4j1Impl(config);
    }
    else if (config.get("log4j2.rootLogger.level") != null) {
        return new LogServiceLog4j2Impl(config);
    }
    else {
        throw new IllegalStateException("Unrecognized configuration");
    }
}

Notice that config object is not being properly instantiated for Log4J2 though it works good for Log4J, Could you please guide me?

Thanks!
Loading...