On 2019/05/22 15:36:11, "Carter Kozak" <cko...@ckozak.net> wrote:
> Once you've implemented a LogEventPatternConverter which overrides
> "handlesThrowable" to return true, you will also need to use that pattern in
> the PatternLayout pattern. This can be a little bit confusing since the
> pattern layout will automatically add a default throwable pattern converter
> to the end without specifying "%ex". This is because alwaysWriteExceptions
> defaults to true, and the pattern doesn't already include a converter which
> returns true from "handlesThrowable". So updating the pattern "%m%n" to
> "%m%n%noMessageThrowable" (replacing "noMessageThrowable" with the pattern
> you have specified on your converter).
>
> Apologies if I've misunderstood the issue.
>
> -ck
> On Wed, May 22, 2019, at 11:21, Matt Sicker wrote:
> > Did you include the @ConverterKeys annotation on your converters? You
> > shouldn't need to make a new layout I think.
> >
> > On Wed, 22 May 2019 at 06:18, 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.
> >
> >
> >
> > --
> > Matt Sicker <boa...@gmail.com>
> >
> Hi Ralph,
I need to support handling of throwables in logging statements.
Case 1: If the layout is PatternLayout, then keep using original log4j2 layout
functionality.
Case 2: If the layout is my custom layout, then just hide the exception message
and keep other layout features as is!
*Note: The log4j2.xml configuration will contain rolling file appenders where
they could either have a patternlayout or a customlayout.
If I just create a new PatternConverter, then it will replace log4j2's
converter keys such as %ex.
I cannot just create a new PatternConverter for this use case, as to handle
throwables, "PatternParser" class has the following code-
if (alwaysWriteExceptions && !handlesThrowable) {
final LogEventPatternConverter pc =
ExtendedThrowablePatternConverter.newInstance(config, null);
list.add(new PatternFormatter(pc, FormattingInfo.getDefault()));
}
Here, the only way to hide throwable message is to replace
"ExtendedThrowablePatternConverter" with my "CustomPatternConverter".
Please assist if there is a better way to do this.