[ 
https://issues.apache.org/jira/browse/LOG4J2-2118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16258289#comment-16258289
 ] 

Remko Popma commented on LOG4J2-2118:
-------------------------------------

I tried to merge the pull request but when I run all tests with
{code}
mvn clean package
{code}
I get many test failures:
{code}
... (many GcFreeLogging tests failures)

I just allocated the object java.util.ArrayList$Itr@3335a837 of type 
java/util/ArrayList$Itr whose size is 32
java.lang.RuntimeException
        at 
org.apache.logging.log4j.core.GcFreeLoggingTestUtil$1.sampleAllocation(GcFreeLoggingTestUtil.java:104)
        at 
com.google.monitoring.runtime.instrumentation.AllocationRecorder.recordAllocation(AllocationRecorder.java:252)
        at java.util.ArrayList.iterator(ArrayList.java:834)
        at java.util.AbstractList.hashCode(AbstractList.java:540)
        at 
java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
        at 
org.apache.logging.log4j.util.PropertiesUtil$Environment.get(PropertiesUtil.java:364)
        at 
org.apache.logging.log4j.util.PropertiesUtil$Environment.access$200(PropertiesUtil.java:310)
        at 
org.apache.logging.log4j.util.PropertiesUtil.getStringProperty(PropertiesUtil.java:258)
        at 
org.apache.logging.log4j.util.PropertiesUtil.getBooleanProperty(PropertiesUtil.java:136)
        at 
org.apache.logging.log4j.util.PropertiesUtil.getBooleanProperty(PropertiesUtil.java:125)
        at 
org.apache.logging.log4j.core.jmx.Server.isJmxDisabled(Server.java:130)
        at 
org.apache.logging.log4j.core.jmx.Server.unregisterLoggerContext(Server.java:242)
        at 
org.apache.logging.log4j.core.LoggerContext.stop(LoggerContext.java:338)
        at 
org.apache.logging.log4j.core.LoggerContext$1.run(LoggerContext.java:279)
        at 
org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry$RegisteredCancellable.run(DefaultShutdownCallbackRegistry.java:109)
        at 
org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:74)
        at java.lang.Thread.run(Thread.java:748)
 expected:<... {aKey=value1, key2=[value2, prop1=value1, prop2=value2} This 
message is logged to the console]> but was:<... {aKey=value1, key2=[TEMP OBJECT 
CREATED!I just allocated the object TEMP OBJECT CREATED!
of type java/nio/HeapCharBuffer whose size is 48]>
[ERROR]   
AsyncLoggerConfigThreadContextCopyOnWriteTest>AbstractAsyncThreadContextTestBase.testAsyncLogWritesToLog:164->AbstractAsyncThreadContextTestBase.checkResult:187
 AsyncLoggerAndAsyncAppenderTest.log: line
66 expected:<...Map LoggerContext i=[66]> but was:<...Map LoggerContext i=[98]>
[ERROR]   
AsyncLoggerConfigThreadContextDefaultTest>AbstractAsyncThreadContextTestBase.testAsyncLogWritesToLog:164->AbstractAsyncThreadContextTestBase.checkResult:187
 AsyncAppenderContextTest.log: line 0 expected:
<...Prop2=configValue2} [WEBAPP DefaultThreadContextMap LoggerContext i=0]> but 
was:<...Prop2=configValue2} [null null null i=null]>
[ERROR]   
AsyncLoggerConfigThreadContextGarbageFreeTest>AbstractAsyncThreadContextTestBase.testAsyncLogWritesToLog:164->AbstractAsyncThreadContextTestBase.checkResult:187
 AsyncLoggerAndAsyncAppenderTest.log: line
69 expected:<...Map LoggerContext i=[69]> but was:<...Map LoggerContext i=[101]>
[ERROR]   NestedLoggingFromToStringTest.testDoublyNestedLogging:133 
expected:<[TRACE 
org.apache.logging.log4j.core.impl.NestedLoggingFromToStringTest.ObjectLoggingThing2
 [ParameterizedLoggingThing x=3 y=4 z=5]]> b
ut was:<[DEBUG 
org.apache.logging.log4j.core.impl.NestedLoggingFromToStringTest.ParameterizedLoggingThing
 getX: values x=3 y=4 z=5]>
{code}

> MutableLogEvent does not retain the Message format string
> ---------------------------------------------------------
>
>                 Key: LOG4J2-2118
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2118
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts
>    Affects Versions: 2.8
>         Environment: Mac OS X 10.11.6
> Java 1.8.0_141
>            Reporter: Zack Slayton
>              Labels: layout
>
> I'm attempting to create a custom binary Layout that stores the provided 
> format string separate from the parameters rather than eagerly formatting 
> them all into a single piece of text. However, when I went to implement 
> `Layout::toByteArray`, I discovered that the `Message::getFormat` method 
> always returns null.
> {code:java}
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
> import org.apache.logging.log4j.core.LogEvent;
> import org.apache.logging.log4j.core.config.plugins.Plugin;
> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
> import org.apache.logging.log4j.core.layout.AbstractLayout;
> import java.io.Serializable;
> import java.util.Arrays;
> @Plugin(name = "MyLayout", category = "Core", elementType = "layout", 
> printObject = true)
> public class MyLayout extends AbstractLayout {
>     public MyLayout() {
>         super(null, null, null);
>     }
>     @PluginFactory
>     public static MyLayout createLayout(){
>         return new MyLayout();
>     }
>     public static void main(String[] args) {
>         Logger log = LogManager.getLogger(MyLayout.class);
>         log.info("Here's a thing: {}. And another: {}", 75, "walrus");
>     }
>     @Override
>     public byte[] toByteArray(LogEvent event) {
>         System.out.println("Format: " + event.getMessage().getFormat());
>         System.out.println("Parameters: " + 
> Arrays.toString(event.getMessage().getParameters()));
>         return new byte[0];
>     }
>     @Override
>     public Serializable toSerializable(LogEvent event) {
>         return null;
>     }
>     @Override
>     public String getContentType() {
>         return null;
>     }
>     @Override
>     public byte[] getFooter() {
>         return new byte[0];
>     }
>     @Override
>     public byte[] getHeader() {
>         return new byte[0];
>     }
> }
> {code}
> If I run `main` (with an extra `PatternLayout`+`Console` appender in my 
> config), I see the following output:
> {code}
> 17:55:28.524 [main] INFO  com.example.logging.plugins.MyLayout - Here's a 
> thing: 75. And another: walrus
> Format: null
> Parameters: [75, walrus]
> {code}
> I had expected to be able to see the format string and the array of 
> parameters, but instead I can only see the parameters. The format string is 
> always null.
> This appears to be due to the implementation of `MutableLogEvent::setMessage` 
> highlighted [in 
> LOG4J2-1510|https://issues.apache.org/jira/browse/LOG4J2-1510]. Because the 
> messages are reusable, they appear to be eagerly formatted and the format 
> string itself is discarded. The `getFormat` method is hardcoded to return 
> `null`.
> Is this by design? If so, what is the prescribed approach to getting the 
> format string in my layout? (Preferably one that does not disable the 
> performance optimizations offered by enabling threadlocals.)
> Thanks!



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to