Colors and Files Appenders (?)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Colors and Files Appenders (?)

Paul Benedict-2
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
Reply | Threaded
Open this post in threaded view
|

Re: Colors and Files Appenders (?)

Ralph Goers
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 <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Colors and Files Appenders (?)

Paul Benedict-2
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
Reply | Threaded
Open this post in threaded view
|

Re: Colors and Files Appenders (?)

Gary Gregory-4
On Mon, Jun 10, 2019 at 4:55 PM Paul Benedict <[hidden email]> 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
>
Reply | Threaded
Open this post in threaded view
|

Re: Colors and Files Appenders (?)

Paul Benedict-2
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 <[hidden email]> wrote:

> On Mon, Jun 10, 2019 at 4:55 PM Paul Benedict <[hidden email]>
> 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
> >
>