You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by James Hart <ha...@gmail.com> on 2014/03/01 01:04:58 UTC

regex to generate a clean text message

Hi

I'm an admin for a java application that uses log4j.

I'm working with a vendor to see if there's a way to scrub the output of
their log messages. The output of these messages is quite long (at least a
few hundred characters) making the lines difficult to read when
troubleshooting.

Is there a way to apply a standard log4j filter or layout that will takes a
regex as input and generate a reduced line with only the bits of text we
care to see?

I thought maybe this RegexFilter would do the trick, but I can't quite tell
by the documentation:

http://logging.apache.org/log4j/2.x/manual/filters.html

Any and all help is much appreciated.

Thank you.

Re: regex to generate a clean text message

Posted by James Hart <ha...@gmail.com>.
AWESOME! Exactly what I was looking for.

Thank you Matt!


On Sat, Mar 1, 2014 at 6:03 PM, Matt Sicker <bo...@gmail.com> wrote:

> I'd also like to add that you can specify the pattern
> %replace{pattern}{regex}{substitution} in a PatternLayout as another way of
> doing this.
>
>
> On 1 March 2014 16:41, Matt Sicker <bo...@gmail.com> wrote:
>
> > I'm sorry, I was slightly wrong. You can indeed do exactly what you're
> > looking for with PatternLayout. See <
> > http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout>
> > for docs. You'll want to use the RegexReplacement configuration. For an
> > example config, check out <
> >
> https://github.com/apache/logging-log4j2/blob/trunk/log4j-core/src/test/resources/log4j-replace.xml
> >.
> > It's pretty simple, no Java code required!
> >
> >
> > On 1 March 2014 12:48, Matt Sicker <bo...@gmail.com> wrote:
> >
> >> The regex filter would filter which messages get logged to the
> configured
> >> logger based on regex pattern matching. What you'd want is a Layout
> >> (probably a PatternLayout) to specify what fields to log. If that
> doesn't
> >> solve the problem, a custom Layout class would probably solve the issue.
> >>
> >>
> >> On 28 February 2014 18:04, James Hart <ha...@gmail.com> wrote:
> >>
> >>> Hi
> >>>
> >>> I'm an admin for a java application that uses log4j.
> >>>
> >>> I'm working with a vendor to see if there's a way to scrub the output
> of
> >>> their log messages. The output of these messages is quite long (at
> least
> >>> a
> >>> few hundred characters) making the lines difficult to read when
> >>> troubleshooting.
> >>>
> >>> Is there a way to apply a standard log4j filter or layout that will
> >>> takes a
> >>> regex as input and generate a reduced line with only the bits of text
> we
> >>> care to see?
> >>>
> >>> I thought maybe this RegexFilter would do the trick, but I can't quite
> >>> tell
> >>> by the documentation:
> >>>
> >>> http://logging.apache.org/log4j/2.x/manual/filters.html
> >>>
> >>> Any and all help is much appreciated.
> >>>
> >>> Thank you.
> >>>
> >>
> >>
> >>
> >> --
> >> Matt Sicker <bo...@gmail.com>
> >>
> >
> >
> >
> > --
> > Matt Sicker <bo...@gmail.com>
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>

Re: regex to generate a clean text message

Posted by Matt Sicker <bo...@gmail.com>.
I'd also like to add that you can specify the pattern
%replace{pattern}{regex}{substitution} in a PatternLayout as another way of
doing this.


On 1 March 2014 16:41, Matt Sicker <bo...@gmail.com> wrote:

> I'm sorry, I was slightly wrong. You can indeed do exactly what you're
> looking for with PatternLayout. See <
> http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout>
> for docs. You'll want to use the RegexReplacement configuration. For an
> example config, check out <
> https://github.com/apache/logging-log4j2/blob/trunk/log4j-core/src/test/resources/log4j-replace.xml>.
> It's pretty simple, no Java code required!
>
>
> On 1 March 2014 12:48, Matt Sicker <bo...@gmail.com> wrote:
>
>> The regex filter would filter which messages get logged to the configured
>> logger based on regex pattern matching. What you'd want is a Layout
>> (probably a PatternLayout) to specify what fields to log. If that doesn't
>> solve the problem, a custom Layout class would probably solve the issue.
>>
>>
>> On 28 February 2014 18:04, James Hart <ha...@gmail.com> wrote:
>>
>>> Hi
>>>
>>> I'm an admin for a java application that uses log4j.
>>>
>>> I'm working with a vendor to see if there's a way to scrub the output of
>>> their log messages. The output of these messages is quite long (at least
>>> a
>>> few hundred characters) making the lines difficult to read when
>>> troubleshooting.
>>>
>>> Is there a way to apply a standard log4j filter or layout that will
>>> takes a
>>> regex as input and generate a reduced line with only the bits of text we
>>> care to see?
>>>
>>> I thought maybe this RegexFilter would do the trick, but I can't quite
>>> tell
>>> by the documentation:
>>>
>>> http://logging.apache.org/log4j/2.x/manual/filters.html
>>>
>>> Any and all help is much appreciated.
>>>
>>> Thank you.
>>>
>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 
Matt Sicker <bo...@gmail.com>

Re: regex to generate a clean text message

Posted by Matt Sicker <bo...@gmail.com>.
I'm sorry, I was slightly wrong. You can indeed do exactly what you're
looking for with PatternLayout. See <
http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout> for
docs. You'll want to use the RegexReplacement configuration. For an example
config, check out <
https://github.com/apache/logging-log4j2/blob/trunk/log4j-core/src/test/resources/log4j-replace.xml>.
It's pretty simple, no Java code required!


On 1 March 2014 12:48, Matt Sicker <bo...@gmail.com> wrote:

> The regex filter would filter which messages get logged to the configured
> logger based on regex pattern matching. What you'd want is a Layout
> (probably a PatternLayout) to specify what fields to log. If that doesn't
> solve the problem, a custom Layout class would probably solve the issue.
>
>
> On 28 February 2014 18:04, James Hart <ha...@gmail.com> wrote:
>
>> Hi
>>
>> I'm an admin for a java application that uses log4j.
>>
>> I'm working with a vendor to see if there's a way to scrub the output of
>> their log messages. The output of these messages is quite long (at least a
>> few hundred characters) making the lines difficult to read when
>> troubleshooting.
>>
>> Is there a way to apply a standard log4j filter or layout that will takes
>> a
>> regex as input and generate a reduced line with only the bits of text we
>> care to see?
>>
>> I thought maybe this RegexFilter would do the trick, but I can't quite
>> tell
>> by the documentation:
>>
>> http://logging.apache.org/log4j/2.x/manual/filters.html
>>
>> Any and all help is much appreciated.
>>
>> Thank you.
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 
Matt Sicker <bo...@gmail.com>

Re: regex to generate a clean text message

Posted by Matt Sicker <bo...@gmail.com>.
The regex filter would filter which messages get logged to the configured
logger based on regex pattern matching. What you'd want is a Layout
(probably a PatternLayout) to specify what fields to log. If that doesn't
solve the problem, a custom Layout class would probably solve the issue.


On 28 February 2014 18:04, James Hart <ha...@gmail.com> wrote:

> Hi
>
> I'm an admin for a java application that uses log4j.
>
> I'm working with a vendor to see if there's a way to scrub the output of
> their log messages. The output of these messages is quite long (at least a
> few hundred characters) making the lines difficult to read when
> troubleshooting.
>
> Is there a way to apply a standard log4j filter or layout that will takes a
> regex as input and generate a reduced line with only the bits of text we
> care to see?
>
> I thought maybe this RegexFilter would do the trick, but I can't quite tell
> by the documentation:
>
> http://logging.apache.org/log4j/2.x/manual/filters.html
>
> Any and all help is much appreciated.
>
> Thank you.
>



-- 
Matt Sicker <bo...@gmail.com>