You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Chathura Priyankara <pr...@gmail.com> on 2015/06/01 11:06:07 UTC

[Dev][log4j2]How to fix printing blank pair of square braces for certain patterns

Hi,

In my log4j2 configuration file, for the pattern converters which don't
have any value to print, the out put in the appender is an empty pair of
square braces "[]".

As an example if we have %x as a pattern converter if the log event doesn't
have any log record in NDC it will print part of empty square braces.

I want to know that whether is the normal behavior ? If so is there any way
that I can set not to print square braces if it doesn't has any log record ?

Thanks!
Chathura.
-- 
Chathura Priyankara,
Faculty of Information Technology,
University of Moratuwa.
Blog  : www.codeoncloud.blogspot.com

Re: [Dev][log4j2]How to fix printing blank pair of square braces for certain patterns

Posted by Gary Gregory <ga...@gmail.com>.
Hi Chathura,

I suppose you could use the PatternLayout's regex and replacement's feature
(https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout).

It does feel like a brute-force solution though.

Perhaps a more elegant solution would be to have a notation in the
PatternLayout that expresses the use of markers on non-empty strings.

Maybe something like %wrap{%x}{[}{]}

I've had a use for something like that in the past as well.

Please create a JIRA to request a feature request. Patches welcome!

Gary

On Mon, Jun 1, 2015 at 2:06 AM, Chathura Priyankara <priyankarahac@gmail.com
> wrote:

>
> Hi,
>
> In my log4j2 configuration file, for the pattern converters which don't
> have any value to print, the out put in the appender is an empty pair of
> square braces "[]".
>
> As an example if we have %x as a pattern converter if the log event
> doesn't have any log record in NDC it will print part of empty square
> braces.
>
> I want to know that whether is the normal behavior ? If so is there any
> way that I can set not to print square braces if it doesn't has any log
> record ?
>
> Thanks!
> Chathura.
> --
> Chathura Priyankara,
> Faculty of Information Technology,
> University of Moratuwa.
> Blog  : www.codeoncloud.blogspot.com
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory