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

Adwait Kumar Singh commented on LOG4J2-2720:
--------------------------------------------

 Project in which I am seeing this is enterprise, though let me see if I can 
recreate it in a sample project and post it on Github.

> TestAppender based on MutableLogEvent stop working in Log4j2.11
> ---------------------------------------------------------------
>
>                 Key: LOG4J2-2720
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2720
>             Project: Log4j 2
>          Issue Type: Question
>    Affects Versions: 2.11.2
>         Environment: JDK 11, Log4J-2.11.2
>            Reporter: Adwait Kumar Singh
>            Priority: Critical
>             Fix For: 2.8
>
>
> I have written unit tests on Logs by creating a custom appender
>  
>  
> After moving to Log4j2.11, I am seeing that the getMessages is returning 
> empty after I am logging something. I attached a debugger and can see that 
> the append() method is being invoked and the message list is getting 
> populated, however at the time of verififcation it is magically vanishing 
> off. Reverting back to 2.8 fixes this.
> {code:java}
> import java.io.Serializable;
> import java.util.ArrayList;
> import java.util.List;
> import org.apache.logging.log4j.core.Filter;
> import org.apache.logging.log4j.core.Layout;
> import org.apache.logging.log4j.core.LogEvent;
> import org.apache.logging.log4j.core.appender.AbstractAppender;
> import org.apache.logging.log4j.core.config.plugins.Plugin;
> import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
> import org.apache.logging.log4j.core.config.plugins.PluginElement;
> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
> import org.apache.logging.log4j.core.impl.MutableLogEvent;
> import org.apache.logging.log4j.core.layout.PatternLayout;
> @Plugin(name = "TestAppender", category = "Core", elementType = "appender", 
> printObject = true)
> public class TestAppender extends AbstractAppender {
>     private List<String> messages = new ArrayList<>();
>     TestAppender(String name, Filter filter, Layout<? extends Serializable> 
> layout) {
>         super(name, filter, layout);
>     }
>     @Override public void append(LogEvent event) { 
>         getMessages().add(((MutableLogEvent) (event)).getFormattedMessage()); 
>     }
>     @PluginFactory public static TestAppender createAppender(
>             @PluginAttribute("name") String name,
>             @PluginElement("Layout") Layout<? extends Serializable> layout,
>             @PluginElement("Filter") final Filter filter,
>             @PluginAttribute("otherAttribute") String otherAttribute) {
>         if (name == null) {
>             LOGGER.error("No name provided for TestAppender");
>             return null;
>         }
>         if (layout == null) { 
>             layout = PatternLayout.createDefaultLayout(); 
>         }
>         return new TestAppender(name, filter, layout);
>     }
>     public List<String> getMessages() {
>         return messages;
>     }
>     public void clearAppender() {
>         this.messages = new ArrayList<>();
>     }
> } {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to