Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2633

JSONLayout can't find Log4jLogEvent["source"] in Java 11

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.11.2
    • Fix Version/s: None
    • Component/s: Layouts
    • Labels:
      None
    • Environment:

      Description

      While migrating my service from Java 8 to Java 11 I noticed that most (if not all) of my logs are missing.

      While looking the the process stderr stream I saw the following message:

       

      ERROR StatusLogger com.fasterxml.jackson.databind.JsonMappingException: No value present (through reference chain: org.apache.logging.log4j.core.impl.Log4jLogEvent["source"])
      com.fasterxml.jackson.databind.JsonMappingException: No value present (through reference chain: org.apache.logging.log4j.core.impl.Log4jLogEvent["source"])
      at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:394)
      at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:353)
      at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316)
      at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFieldsFiltered(BeanSerializerBase.java:779)
      at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:153)
      at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
      at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
      at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1396)
      at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1120)
      at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:966)
      at org.apache.logging.log4j.core.layout.AbstractJacksonLayout.toSerializable(AbstractJacksonLayout.java:304)
      at org.apache.logging.log4j.core.layout.JsonLayout.toSerializable(JsonLayout.java:291)
      at org.apache.logging.log4j.core.layout.AbstractJacksonLayout.toSerializable(AbstractJacksonLayout.java:255)
      at org.apache.logging.log4j.core.layout.JsonLayout.toSerializable(JsonLayout.java:68)
      at org.apache.logging.log4j.core.layout.AbstractJacksonLayout.toSerializable(AbstractJacksonLayout.java:44)
      at org.apache.logging.log4j.core.layout.AbstractStringLayout.toByteArray(AbstractStringLayout.java:304)
      at com.moblica.log4j.ScribeAppender.append(ScribeAppender.java:90)
      at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
      at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.callAppenders(AsyncAppender.java:454)
      at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.run(AsyncAppender.java:407)
      Caused by: java.util.NoSuchElementException: No value present
      at java.base/java.util.Optional.get(Optional.java:148)
      at org.apache.logging.log4j.util.StackLocator.calcLocation(StackLocator.java:79)
      at org.apache.logging.log4j.util.StackLocatorUtil.calcLocation(StackLocatorUtil.java:71)
      at org.apache.logging.log4j.core.impl.Log4jLogEvent.getSource(Log4jLogEvent.java:669)
      at jdk.internal.reflect.GeneratedMethodAccessor446.invoke(Unknown Source)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688)
      at com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter.serializeAsField(SimpleBeanPropertyFilter.java:208)
      at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFieldsFiltered(BeanSerializerBase.java:771)
      ... 19 more
      

      When using the Console appender with PatternLayout I was able to see the missing logs.

      Looking at my config I noticed that I set the JSONLayout.locationInfo to true. After changing it to false I was able to see my logs with the the JSONLayout properly.

      I did saw some logs when setting SONLayout.locationInfo to true, for example logs from the com.google.common.cache.LocalCache class (sorry but I can't share the actual exception due to legal reasons).

      I'm not familiar with the log4j internals, but this seems like an issue with Java 11 (or maybe > 8) and the JSONLayout.locationInfo setting.

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ran.leibman Ran Leibman
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: