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 Paul Benedict <pb...@apache.org> on 2019/06/10 19:18:31 UTC

Colors and Files Appenders (?)

To stop me hardcoding repetitive patterns in Appenders, I defined several
<Property> elements as such. Most my Appenders go to files and a couple to
the console. In addition, to prevent a multiplicity of plain-text vs. color
text patterns, I defined color conversions in my patterns.

Clearly, this dual purpose doesn't work.

My log files have escape characters in them. I understand why (ANSI color
escape sequences), but I am really *surprised* to see them! Perhaps this
was a bad assumption of mine, but .... it seemed absolutely natural/obvious
to me that files have no colors. Thus, I was not expecting those color
conversions to pose interference.

Does a use case exist for putting "colors" in files? If not, shouldn't a
file Appender just elide that styling?

PS: I am using Log4J2 version 2.11.2.

Cheers and God bless,
Paul

Re: Colors and Files Appenders (?)

Posted by Paul Benedict <pb...@apache.org>.
That's a good point.

Well... In between responses, I was excited to stumble upon a possible
silver bullet. There is a "disableAnsi" attribute on the pattern layout
[1]. Trying it on my file appenders, I can say most of my log files are now
without ANSI escape codes. That's good!

However, I still got a few. It's an oddity and possible edge case. If the
message (%m) includes ANSI escape codes, those are passed right through. So
I guess "disableAnsi" is only a filter for the layout "pattern" and not the
message itself?

And what do you guys think of this behavior?

[1]
https://logging.apache.org/log4j/log4j-2.4/manual/layouts.html#PatternLayout

Cheers and God bless,
Paul


On Mon, Jun 10, 2019 at 3:59 PM Gary Gregory <ga...@gmail.com> wrote:

> On Mon, Jun 10, 2019 at 4:55 PM Paul Benedict <pb...@apache.org>
> wrote:
>
> > Pattern converters don't have the intelligence. I agree. However,
> > converters don't exist for their own sake -- they exist for layouts and
> > ultimately for Appenders. Those are the instances that have the
> > intelligence to make sense out of themselves. Even more so is the
> Processor
> > to make sense out of the configuration file.
> >
> > Hence my original question:
> >
> > Does it make sense for a File Appender to emit "colors"?
> >
>
> It does if you want to later output the file to a console.
>
> Gary
>
>
> >
> > If it does, then okay, but I'd like to hear the concrete justification
> one
> > way or another. I am interested in the purpose.
> >
> > Cheers and God bless,
> > Paul
> >
>

Re: Colors and Files Appenders (?)

Posted by Gary Gregory <ga...@gmail.com>.
On Mon, Jun 10, 2019 at 4:55 PM Paul Benedict <pb...@apache.org> wrote:

> Pattern converters don't have the intelligence. I agree. However,
> converters don't exist for their own sake -- they exist for layouts and
> ultimately for Appenders. Those are the instances that have the
> intelligence to make sense out of themselves. Even more so is the Processor
> to make sense out of the configuration file.
>
> Hence my original question:
>
> Does it make sense for a File Appender to emit "colors"?
>

It does if you want to later output the file to a console.

Gary


>
> If it does, then okay, but I'd like to hear the concrete justification one
> way or another. I am interested in the purpose.
>
> Cheers and God bless,
> Paul
>

Re: Colors and Files Appenders (?)

Posted by Paul Benedict <pb...@apache.org>.
Pattern converters don't have the intelligence. I agree. However,
converters don't exist for their own sake -- they exist for layouts and
ultimately for Appenders. Those are the instances that have the
intelligence to make sense out of themselves. Even more so is the Processor
to make sense out of the configuration file.

Hence my original question:

Does it make sense for a File Appender to emit "colors"?

If it does, then okay, but I'd like to hear the concrete justification one
way or another. I am interested in the purpose.

Cheers and God bless,
Paul

Re: Colors and Files Appenders (?)

Posted by Ralph Goers <ra...@dslextreme.com>.
The Layout just formats the data as you direct it to. Pattern Converters don’t have the intelligence to know whether they are targeting a Console or a File.  You need to provide the pattern that is appropriate for the instance of the Layout you want depending on what Appender it is in.

Ralph

> On Jun 10, 2019, at 12:18 PM, Paul Benedict <pb...@apache.org> wrote:
> 
> To stop me hardcoding repetitive patterns in Appenders, I defined several
> <Property> elements as such. Most my Appenders go to files and a couple to
> the console. In addition, to prevent a multiplicity of plain-text vs. color
> text patterns, I defined color conversions in my patterns.
> 
> Clearly, this dual purpose doesn't work.
> 
> My log files have escape characters in them. I understand why (ANSI color
> escape sequences), but I am really *surprised* to see them! Perhaps this
> was a bad assumption of mine, but .... it seemed absolutely natural/obvious
> to me that files have no colors. Thus, I was not expecting those color
> conversions to pose interference.
> 
> Does a use case exist for putting "colors" in files? If not, shouldn't a
> file Appender just elide that styling?
> 
> PS: I am using Log4J2 version 2.11.2.
> 
> Cheers and God bless,
> Paul



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org