PatternLayout isn’t really designed to use an alternate implementation of 
PatternParser. Why do you need one? A custom Layout wouldn’t normally use a 
PatternParser, only PatternLayout and you shouldn’t need to modify that either.

Just create a new PatternConverter that does what you need it to do. 

Ralph

> On May 22, 2019, at 4:18 AM, Gaurav <gaurav9...@gmail.com> wrote:
> 
> 
> 
> On 2019/05/16 14:59:56, Matt Sicker <boa...@gmail.com> wrote: 
>> Instead of extending the plugin classes, you can create your own
>> plugins. PatternConverters are relatively trivial plugins, so I
>> wouldn't worry too much about code duplication.
>> 
>> I could be missing a feature, though.
>> 
>> On Thu, 16 May 2019 at 09:32, Gaurav <gaurav9...@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> I want to hide the message in the throwable.
>>> 
>>> What I've tried -
>>> 1. Create a custom layout by extending AbstractStringLayout.
>>> 2. Create a pattern parser.
>>> 3. Create a pattern converter by extending ThrowablePatternConverter.
>>> 
>>> Is there a simpler way to do this?
>>> 
>>> In log4j1.2, it was simple to just extend the classes, but the classes in 
>>> log4j2 are final.
>>> 
>>> Please assist.
>> 
>> 
>> 
>> -- 
>> Matt Sicker <boa...@gmail.com>
>> Hi,
> I've created - 
> 1.A custom pattern converter plugin extending LogEventPatternConverter
> 2.A custom layout plugin extending AbstractStringLayout.
> 3.A custom pattern parser similar to "PatternParser" class in log4j2.
> 
> But, as, I am dealing with throwables and cannot modify log4j2 jar, I need to 
> plug the custom pattern converter instance in my parser class.
> 
> if (alwaysWriteExceptions && !handlesThrowable) {
>            final LogEventPatternConverter pc = 
> TestPatternConverter.newInstance();
>            list.add(new PatternFormatter(pc, FormattingInfo.getDefault()));
> }
> 
> But, at the startup, it is throwing the following exception - 
> 
> Caused by: java.lang.ClassCastException: com.test.TestPatternParser cannot be 
> cast to org.apache.logging.log4j.core.pattern.PatternParser
>        at 
> org.apache.logging.log4j.core.layout.PatternLayout.createPatternParser(PatternLayout.java:244)
>        at 
> org.apache.logging.log4j.core.layout.PatternLayout$SerializerBuilder.build(PatternLayout.java:375)
>        ... 32 more
> 
> Please assist.
> 


Reply via email to