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 Gary Gregory <ga...@gmail.com> on 2013/09/12 05:12:37 UTC

How to...

Hi All:

Here is my pickle:

I have a stock XML config file I package with a standalone app.

When I run it on the Windows command line, I want to use a JAnsi logger, it
works.

When I run the app within Eclipse, the Eclipse console displays junk for
the escape codes, not so nice.

So I'd like Log4J to use a plain Console appender in this case.

The question is:

Should Log4J detect that there is no real console? If you call
"java.io.Console.console()" from Eclipse, you get null, so that would be
one way to gracefully detect that there is no console.

Or:

Should I be able to have some condition in the config that says if ...
enable this appender else enable that one.

Or:

Should I be able to configure each appender with an "unless" attibute (like
in Ant) that tells Log4j to enable the appender unless some condition is
not met. It could be "if" instead of "unless" but you get the idea.

Thoughts?

-- 
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

Re: How to...

Posted by Gary Gregory <ga...@gmail.com>.
Since JavaScript is baked in Java 6, that would be the way to go, JS
expressions in attributes or element values.

Right now, I think I'd like to have a Console or more likely a
PatternLayout attribute called "keepAnsiIfNoConsole=true" or
"noConsoleAnsi=true" (can't think of a better name at this hour) if you
REALLY want ANSI if there is no console, which you actually DO want for out
unit tests.

Gary


On Thu, Sep 12, 2013 at 12:44 AM, Ralph Goers <ra...@dslextreme.com>wrote:

> That is one way to do it.  I wouldn't mind adding logic into the
> configuration but I'd hate to do that in XML - then it will look like Maven
> 1 with Jelly.
>
> Ralph
>
>
>
> On Sep 11, 2013, at 9:26 PM, Gary Gregory wrote:
>
> Hi All,
>
> I have a solution implemented locally that does not output ANSI escapes if
> there is no console (it logs a warning to the status logger if it detects
> this condition on start up).
>
> I am wondering if the Console element should have an attribute called
> "autoHideAnsi" or some such to still output ANSI escapes even if there is
> no console.
>
> Gary
>
>
> On Wed, Sep 11, 2013 at 11:12 PM, Gary Gregory <ga...@gmail.com>wrote:
>
>> Hi All:
>>
>> Here is my pickle:
>>
>> I have a stock XML config file I package with a standalone app.
>>
>> When I run it on the Windows command line, I want to use a JAnsi logger,
>> it works.
>>
>> When I run the app within Eclipse, the Eclipse console displays junk for
>> the escape codes, not so nice.
>>
>> So I'd like Log4J to use a plain Console appender in this case.
>>
>> The question is:
>>
>> Should Log4J detect that there is no real console? If you call
>> "java.io.Console.console()" from Eclipse, you get null, so that would be
>> one way to gracefully detect that there is no console.
>>
>> Or:
>>
>> Should I be able to have some condition in the config that says if ...
>> enable this appender else enable that one.
>>
>> Or:
>>
>> Should I be able to configure each appender with an "unless" attibute
>> (like in Ant) that tells Log4j to enable the appender unless some condition
>> is not met. It could be "if" instead of "unless" but you get the idea.
>>
>> Thoughts?
>>
>> --
>> 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
>>
>
>
>
> --
> 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
>
>
>


-- 
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

Re: How to...

Posted by Ralph Goers <ra...@dslextreme.com>.
That is one way to do it.  I wouldn't mind adding logic into the configuration but I'd hate to do that in XML - then it will look like Maven 1 with Jelly.  

Ralph


On Sep 11, 2013, at 9:26 PM, Gary Gregory wrote:

> Hi All,
> 
> I have a solution implemented locally that does not output ANSI escapes if there is no console (it logs a warning to the status logger if it detects this condition on start up).
> 
> I am wondering if the Console element should have an attribute called "autoHideAnsi" or some such to still output ANSI escapes even if there is no console.
> 
> Gary
> 
> 
> On Wed, Sep 11, 2013 at 11:12 PM, Gary Gregory <ga...@gmail.com> wrote:
> Hi All:
> 
> Here is my pickle:
> 
> I have a stock XML config file I package with a standalone app.
> 
> When I run it on the Windows command line, I want to use a JAnsi logger, it works.
> 
> When I run the app within Eclipse, the Eclipse console displays junk for the escape codes, not so nice.
> 
> So I'd like Log4J to use a plain Console appender in this case.
> 
> The question is:
> 
> Should Log4J detect that there is no real console? If you call "java.io.Console.console()" from Eclipse, you get null, so that would be one way to gracefully detect that there is no console.
> 
> Or:
> 
> Should I be able to have some condition in the config that says if ... enable this appender else enable that one.
> 
> Or:
> 
> Should I be able to configure each appender with an "unless" attibute (like in Ant) that tells Log4j to enable the appender unless some condition is not met. It could be "if" instead of "unless" but you get the idea.
> 
> Thoughts?
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory


Re: How to...

Posted by Gary Gregory <ga...@gmail.com>.
Hi All:

I have attached a patch to a new issue: LOG4J2-413 "PatternLayout option to
not output ANSI escape codes if no Console is available"

https://issues.apache.org/jira/browse/LOG4J2-413

Can anyone think of a better way to do this?

It would be easy to offer this without any option. But as I describe in the
issue, I think it should be an option. I found it hard to connect the
configuration to the code that needs to know it. Too hard in fact. It feels
like something is missing in the configuration. I suppose this is not a
point of view the code has needed before.

Please advise.

Thank you,
Gary


On Tue, Sep 24, 2013 at 9:49 AM, Gary Gregory <ga...@gmail.com>wrote:

> On Thu, Sep 12, 2013 at 12:26 AM, Gary Gregory <ga...@gmail.com>wrote:
>
>> Hi All,
>>
>> I have a solution implemented locally that does not output ANSI escapes
>> if there is no console (it logs a warning to the status logger if it
>> detects this condition on start up).
>>
>> I am wondering if the Console element should have an attribute called
>> "autoHideAnsi" or some such to still output ANSI escapes even if there is
>> no console.
>>
>
> Coming back to this, I think the simplest solution is to add an attribute
> to PatternLayout. Does anyone have a better name than autoHideAnsi?
>
> Gary
>
>
>> Gary
>>
>>
>> On Wed, Sep 11, 2013 at 11:12 PM, Gary Gregory <ga...@gmail.com>wrote:
>>
>>> Hi All:
>>>
>>> Here is my pickle:
>>>
>>> I have a stock XML config file I package with a standalone app.
>>>
>>> When I run it on the Windows command line, I want to use a JAnsi logger,
>>> it works.
>>>
>>> When I run the app within Eclipse, the Eclipse console displays junk for
>>> the escape codes, not so nice.
>>>
>>> So I'd like Log4J to use a plain Console appender in this case.
>>>
>>> The question is:
>>>
>>> Should Log4J detect that there is no real console? If you call
>>> "java.io.Console.console()" from Eclipse, you get null, so that would be
>>> one way to gracefully detect that there is no console.
>>>
>>> Or:
>>>
>>> Should I be able to have some condition in the config that says if ...
>>> enable this appender else enable that one.
>>>
>>> Or:
>>>
>>> Should I be able to configure each appender with an "unless" attibute
>>> (like in Ant) that tells Log4j to enable the appender unless some condition
>>> is not met. It could be "if" instead of "unless" but you get the idea.
>>>
>>> Thoughts?
>>>
>>> --
>>> 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
>>>
>>
>>
>>
>> --
>> 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
>>
>
>
>
> --
> 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
>



-- 
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

Re: How to...

Posted by Gary Gregory <ga...@gmail.com>.
On Thu, Sep 12, 2013 at 12:26 AM, Gary Gregory <ga...@gmail.com>wrote:

> Hi All,
>
> I have a solution implemented locally that does not output ANSI escapes if
> there is no console (it logs a warning to the status logger if it detects
> this condition on start up).
>
> I am wondering if the Console element should have an attribute called
> "autoHideAnsi" or some such to still output ANSI escapes even if there is
> no console.
>

Coming back to this, I think the simplest solution is to add an attribute
to PatternLayout. Does anyone have a better name than autoHideAnsi?

Gary


> Gary
>
>
> On Wed, Sep 11, 2013 at 11:12 PM, Gary Gregory <ga...@gmail.com>wrote:
>
>> Hi All:
>>
>> Here is my pickle:
>>
>> I have a stock XML config file I package with a standalone app.
>>
>> When I run it on the Windows command line, I want to use a JAnsi logger,
>> it works.
>>
>> When I run the app within Eclipse, the Eclipse console displays junk for
>> the escape codes, not so nice.
>>
>> So I'd like Log4J to use a plain Console appender in this case.
>>
>> The question is:
>>
>> Should Log4J detect that there is no real console? If you call
>> "java.io.Console.console()" from Eclipse, you get null, so that would be
>> one way to gracefully detect that there is no console.
>>
>> Or:
>>
>> Should I be able to have some condition in the config that says if ...
>> enable this appender else enable that one.
>>
>> Or:
>>
>> Should I be able to configure each appender with an "unless" attibute
>> (like in Ant) that tells Log4j to enable the appender unless some condition
>> is not met. It could be "if" instead of "unless" but you get the idea.
>>
>> Thoughts?
>>
>> --
>> 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
>>
>
>
>
> --
> 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
>



-- 
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

Re: How to...

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

I have a solution implemented locally that does not output ANSI escapes if
there is no console (it logs a warning to the status logger if it detects
this condition on start up).

I am wondering if the Console element should have an attribute called
"autoHideAnsi" or some such to still output ANSI escapes even if there is
no console.

Gary


On Wed, Sep 11, 2013 at 11:12 PM, Gary Gregory <ga...@gmail.com>wrote:

> Hi All:
>
> Here is my pickle:
>
> I have a stock XML config file I package with a standalone app.
>
> When I run it on the Windows command line, I want to use a JAnsi logger,
> it works.
>
> When I run the app within Eclipse, the Eclipse console displays junk for
> the escape codes, not so nice.
>
> So I'd like Log4J to use a plain Console appender in this case.
>
> The question is:
>
> Should Log4J detect that there is no real console? If you call
> "java.io.Console.console()" from Eclipse, you get null, so that would be
> one way to gracefully detect that there is no console.
>
> Or:
>
> Should I be able to have some condition in the config that says if ...
> enable this appender else enable that one.
>
> Or:
>
> Should I be able to configure each appender with an "unless" attibute
> (like in Ant) that tells Log4j to enable the appender unless some condition
> is not met. It could be "if" instead of "unless" but you get the idea.
>
> Thoughts?
>
> --
> 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
>



-- 
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