I was previously bridging JUL to SLF4J (org.slf4j.jul-to-slf4j) and then from SLF4j to Log4j(org.apache.logging.log4j.log4j-slf4j-impl) though utilised ThreadContext within my code rather than SLF4J MDC. I also set the following flag on run: java.util.logging.manager=org.apache.logging.log4j.jul.LogManager
Noticing the performance impact with bridging from JUL to SLF4J. I have also tried directly bridging from jul to log4j with lof4j-jul-2.12.1.jar which seems to format the jul messages according to log4j2.xml though the thread context is being lost as soon as I enter log4j code and so MDC is not working for JUL logs. The logs below may shed some insight on this. I'm not sure where slf4j-jdk14-1.7.25.jar is being picked up from given it's not within my pom.xml. Also my tomcat log4j2 lib folder includes log4j-api, log4j-appserver, log4j-jul, log4j-core. My pom file includes log4j-api and log4j-slf4j-impl. I also previously had log4j-jul within the pom though that didn't seem to make a difference. There is conflicting documentation/information floating around regarding dependencies so I may have missed something. SLF4J: Class path contains multiple SLF4J bindings. > SLF4J: Found binding in > [jar:file:/home/abdullah/Desktop/apache-tomcat-8.5.50/webapps/emerald-decaf/WEB-INF/lib/log4j-slf4j-impl-2.12.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] > SLF4J: Found binding in > [jar:file:/home/abdullah/Desktop/apache-tomcat-8.5.50/webapps/emerald-decaf/WEB-INF/lib/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] > SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an > explanation. > SLF4J: Actual binding is of type > [org.apache.logging.slf4j.Log4jLoggerFactory] > DEBUG StatusLogger Unable to retrieve provider from ClassLoader > java.net.URLClassLoader@6e4566f1 > java.util.ServiceConfigurationError: > org.apache.logging.log4j.spi.Provider: Provider > org.apache.logging.log4j.core.impl.Log4jProvider not a subtype > at java.util.ServiceLoader.fail(ServiceLoader.java:239) > at java.util.ServiceLoader.access$300(ServiceLoader.java:185) > at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376) > at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) > at java.util.ServiceLoader$1.next(ServiceLoader.java:480) > at > org.apache.logging.log4j.util.ProviderUtil.loadProviders(ProviderUtil.java:109) > at org.apache.logging.log4j.util.ProviderUtil.<init>(ProviderUtil.java:68) > at > org.apache.logging.log4j.util.ProviderUtil.lazyInit(ProviderUtil.java:150) > at > org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:134) > at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:89) > at > org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:138) > at > org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:45) > at > org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:48) > at > org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:30) > at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358) > at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383) > at > com.matillion.bi.cactus.server.ContextListener.<clinit>(ContextListener.java:23) > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) > at > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) > at java.lang.reflect.Constructor.newInstance(Constructor.java:423) > at > org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151) > at > org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4621) > at > org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165) > at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) > at > org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743) > at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719) > at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705) > at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1720) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at > org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) > at > com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) > at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) > at > org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:479) > at > org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:428) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at > org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) > at > com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) > at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) > at > com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468) > at > javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) > at > javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) > at > javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) > at java.security.AccessController.doPrivileged(Native Method) > at > javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408) > at > javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) > at sun.rmi.transport.Transport$1.run(Transport.java:200) > at sun.rmi.transport.Transport$1.run(Transport.java:197) > at java.security.AccessController.doPrivileged(Native Method) > at sun.rmi.transport.Transport.serviceCall(Transport.java:196) > at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) > at > sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) > at > sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) > at java.security.AccessController.doPrivileged(Native Method) > at > sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) > at java.lang.Thread.run(Thread.java:748) > DEBUG StatusLogger Unable to retrieve provider from ClassLoader > sun.misc.Launcher$AppClassLoader@18b4aac2 > java.util.ServiceConfigurationError: > org.apache.logging.log4j.spi.Provider: Provider > org.apache.logging.log4j.core.impl.Log4jProvider not a subtype > at java.util.ServiceLoader.fail(ServiceLoader.java:239) > at java.util.ServiceLoader.access$300(ServiceLoader.java:185) > at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376) > at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) > at java.util.ServiceLoader$1.next(ServiceLoader.java:480) > at > org.apache.logging.log4j.util.ProviderUtil.loadProviders(ProviderUtil.java:109) > at org.apache.logging.log4j.util.ProviderUtil.<init>(ProviderUtil.java:68) > at > org.apache.logging.log4j.util.ProviderUtil.lazyInit(ProviderUtil.java:150) > at > org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:134) > at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:89) > at > org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:138) > at > org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:45) > at > org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:48) > at > org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:30) > at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358) > at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383) > at > com.matillion.bi.cactus.server.ContextListener.<clinit>(ContextListener.java:23) > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) > at > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) > at java.lang.reflect.Constructor.newInstance(Constructor.java:423) > at > org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151) > at > org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4621) > at > org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165) > at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) > at > org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743) > at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719) > at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705) > at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1720) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at > org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) > at > com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) > at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) > at > org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:479) > at > org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:428) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at > org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) > at > com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) > at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) > at > com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468) > at > javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) > at > javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) > at > javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) > at java.security.AccessController.doPrivileged(Native Method) > at > javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408) > at > javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) > at sun.rmi.transport.Transport$1.run(Transport.java:200) > at sun.rmi.transport.Transport$1.run(Transport.java:197) > at java.security.AccessController.doPrivileged(Native Method) > at sun.rmi.transport.Transport.serviceCall(Transport.java:196) > at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) > at > sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) > at > sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) > at java.security.AccessController.doPrivileged(Native Method) > at > sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) > at java.lang.Thread.run(Thread.java:748) > DEBUG StatusLogger Using ShutdownCallbackRegistry class > org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry > DEBUG StatusLogger Took 0.108460 seconds to load 211 plugins from > ParallelWebappClassLoader > context: emerald-decaf > delegate: false > ----------> Parent Classloader: > java.net.URLClassLoader@6e4566f1 > > DEBUG StatusLogger PluginManager 'Converter' found 44 plugins > DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false-1 > DEBUG StatusLogger Starting LoggerContext[name=44ccb73c, > org.apache.logging.log4j.core.LoggerContext@5a4cc2cb]... > DEBUG StatusLogger Reconfiguration started for context[name=44ccb73c] at > URI null (org.apache.logging.log4j.core.LoggerContext@5a4cc2cb) with > optional ClassLoader: null > DEBUG StatusLogger PluginManager 'ConfigurationFactory' found 4 plugins > DEBUG StatusLogger Missing dependencies for Yaml support, > ConfigurationFactory > org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory is > inactive > DEBUG StatusLogger Using configurationFactory > org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@5b9c071b > DEBUG StatusLogger Closing ByteArrayInputStream > java.io.ByteArrayInputStream@26d94ebf > I've since reverted the JUL to SLF4J bridget On Sat, 18 Apr 2020 at 05:47, Ralph Goers <ralph.go...@dslextreme.com> wrote: > If you are using SLF4J to add to the MDC, the classes in log4j-slf4j-impl > will update Log4j’s ThreadContext (a ThreadLocal Map) under the covers. > Regardless of what API you use for logging, when they are bridged to > log4j-core it will locate the ThreadContext and retrieve whatever is in it. > > What mechanism are you using to cause JUL log events to end up in Log4j? > > Ralph > > > On Apr 17, 2020, at 9:17 AM, Abdul <abdul.huss...@matillion.com.INVALID> > wrote: > > > > Hey, > > > > So I've just switched my logging framework to Log4j2 to leverage it's > support for MDC. Given that I've used a mixture of SLF4J and JUL log > messages within my code I've decided to leverage Log4j ability to convert > JUL log messages to Log4j2 messages. I've set the following flag to my > application > -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager and > added all the required jars. Logging seems to be working pretty good in > that my SLF4J and JUL messages are being formatted according to my log4j2 > config file I added a Hello prefix to each message, though MDC seems to not > be picked up with the JUL messages. > > > > From debugging when I use the SLF4J logger it calls Log4jLogger which is > preserving the ThreadContext whereas my JUL log messages are > re-initializing the ThreadContext as soon as they enter AbstractLogger. > > > > > > Anyone know if it's possible to preserve ThreadContext with JUL messages > being converted to Log4j2 messages or is there a potential alternative > method I can look into? > > > > > > My Log4j2.xml config file: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <Configuration status="INFO"> > > <Appenders> > > <Console name="Console" target="SYSTEM_OUT"> > > <PatternLayout pattern="Hello %X{Organisation} > %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> > > </Console> > > </Appenders> > > <Loggers> > > <Root level="info"> > > <AppenderRef ref="Console"/> > > </Root> > > </Loggers> > > </Configuration> > > > > Regards, > > > > Abdul Haseeb Hussain > > > > > > -- > > > > > > *The information in this email is confidential and solely for the use of > the intended recipient(s). If you receive this email in error, please > notify the sender and delete the email from your system immediately. In > such circumstances, you must not make any use of the email or its contents. > Views expressed by an individual in this email do not necessarily reflect > the views of Matillion Ltd. > > > > * > > > > *Matillion Ltd accepts no responsibility for any damage caused by > malicious software transmitted by email. Email transmission cannot be > guaranteed to be secure and error free, it is possible for it to be > intercepted, lost, destroyed, later, incomplete or with added malware. The > sender does not accept liability for any errors or omissions in the > contents of this message, which arise as a result of email transmission > > > > * > > > > *Matillion Ltd, Station House, Stamford New Road, Altrincham, England, > WA14 1EP (Main and registered office address). *_Company number: 07474948._ > > > > > -- *The information in this email is confidential and solely for the use of the intended recipient(s). If you receive this email in error, please notify the sender and delete the email from your system immediately. In such circumstances, you must not make any use of the email or its contents. Views expressed by an individual in this email do not necessarily reflect the views of Matillion Ltd. * *Matillion Ltd accepts no responsibility for any damage caused by malicious software transmitted by email. Email transmission cannot be guaranteed to be secure and error free, it is possible for it to be intercepted, lost, destroyed, later, incomplete or with added malware. The sender does not accept liability for any errors or omissions in the contents of this message, which arise as a result of email transmission * *Matillion Ltd, Station House, Stamford New Road, Altrincham, England, WA14 1EP (Main and registered office address). *_Company number: 07474948._