Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-16342

<JsonLayout /> not working

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • 8.11.2
    • None
    • Docker
    • None

    Description

      We customized a solr 8.1.2 docker image by adding a custom log4j2 configuration in order to log in json format.

      The custom configuration is simply replacing the <PatternLayout> with <JsonLayout> in the main log file:

      <RollingRandomAccessFile
              name="MainLogFile"
              fileName="${sys:solr.log.dir}/solr.log"
              filePattern="${sys:solr.log.dir}/solr.log.%i" >
          <JsonLayout />
          <Policies>
              <OnStartupTriggeringPolicy />
              <SizeBasedTriggeringPolicy size="32 MB"/>
          </Policies>
          <DefaultRolloverStrategy max="10"/>
      </RollingRandomAccessFile> 

      We then set the LOG4J_PROPS variable point to the custom log4j configuration.
      It is not working due to this error:

      ERROR Could not create plugin of type class org.apache.logging.log4j.core.layout.JsonLayout for element JsonLayout: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider
      	at org.apache.logging.log4j.core.layout.JsonLayout.<init>(JsonLayout.java:159)
      	at org.apache.logging.log4j.core.layout.JsonLayout.<init>(JsonLayout.java:71)
      	at org.apache.logging.log4j.core.layout.JsonLayout$Builder.build(JsonLayout.java:103)
      	at org.apache.logging.log4j.core.layout.JsonLayout$Builder.build(JsonLayout.java:79)
      	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1120)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1045)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1037)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1037)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:651)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:247)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:293)
      	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:626)
      	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:699)
      	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716)
      	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270)
      	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
      	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
      	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
      	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137)
      	at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:55)
      	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
      	at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
      	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
      	at org.eclipse.jetty.util.log.Slf4jLog.<init>(Slf4jLog.java:36)
      	at org.eclipse.jetty.util.log.Slf4jLog.<init>(Slf4jLog.java:30)
      	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
      	at org.eclipse.jetty.util.log.Log.initialized(Log.java:158)
      	at org.eclipse.jetty.util.log.Log.getLogger(Log.java:278)
      	at org.eclipse.jetty.util.log.Log.getLogger(Log.java:267)
      	at org.eclipse.jetty.xml.XmlConfiguration.<clinit>(XmlConfiguration.java:88)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      	at org.eclipse.jetty.start.Main.invokeMain(Main.java:218)
      	at org.eclipse.jetty.start.Main.start(Main.java:491)
      	at org.eclipse.jetty.start.Main.main(Main.java:77)
      Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ser.FilterProvider
      	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
      	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
      	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
      	... 41 more
      

      It seems that the jackson library is not in the classpath.
      As a workaround we symlinked the jackson libraries that exists in the /opt/solr/server/solr-webapp/webapp/WEB-INF/lib/ directory to /opt/solr/server/lib/ext/ while building the docker image:

      ...
      RUN ln -s /opt/solr/server/solr-webapp/webapp/WEB-INF/lib/jackson-core-2.13.3.jar /opt/solr/server/lib/ext/jackson-core-2.13.3.jar && \
          ln -s /opt/solr/server/solr-webapp/webapp/WEB-INF/lib/jackson-databind-2.13.3.jar /opt/solr/server/lib/ext/jackson-databind-2.13.3.jar && \
          ln -s /opt/solr/server/solr-webapp/webapp/WEB-INF/lib/jackson-annotations-2.13.3.jar /opt/solr/server/lib/ext/jackson-annotations-2.13.3.jar
      ...
      

      The expected behavior is that it should work "out of the box" since the json log is also mentioned in the documentation in https://solr.apache.org/guide/8_11/configuring-logging.html

      Attachments

        Activity

          People

            Unassigned Unassigned
            zaccheob Zaccheo Bagnati
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: