You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Antoine Levy-Lambert <an...@gmx.de> on 2005/01/10 22:25:51 UTC

Re: Avoiding logging loops

Hello Ceki,

I have not had the time to check your suggested code modification, but 
it makes sense to avoid these infinite loops.

What do other ant committers think ?

(I have moved the discussion to dev@ant, I think this is more appropriate).

Antoine

Ceki Gülcü wrote:

>
> Hello,
>
> While running test cases for log4j, I have noticed that our latest
> version produces an infinite loop in Project.fireMessageLoggedEvent()
> since in our test version, org.apache.log4j.Logger.getLogger()
> generates output on the console, which triggers another call to
> fireMessageLoggedEvent, hence the infinite loop.
>
> Would it be possible to modify Project.fireMessageLoggedEvent() so
> that it ignores recursive calls to fireMessageLogged() instead of
> throwing a BuildException? Here is the proposed change:
>
> NOW:
>
>    synchronized (this) {
>       if (loggingMessage) {
>          throw new BuildException("Listener attempted to access "
>               + (priority == MSG_ERR ? "System.err" : "System.out")
>               + " with message [" + message
>               + "] - infinite loop terminated");
>       }
>
>       try {
>          loggingMessage = true;
>          Iterator iter = listeners.iterator();
>          while (iter.hasNext()) {
>             BuildListener listener = (BuildListener) iter.next();
>             listener.messageLogged(event);
>           }
>       } finally {
>         loggingMessage = false;
>       }
>    }
>
> PROPOSED CHANGE:
>
>    synchronized (this) {
>      if (loggingMessage) {
>        return;
>      }
>      ... the rest remains the same
>
>
>
> If this change is unacceptable, would you consider adding infinite
> loop detection in Log4jListener.messageLogged(BuildEvent event)?
>
> Many thanks in advance,
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Avoiding logging loops

Posted by Stefan Bodewig <bo...@apache.org>.
I've changed Ant's CVS HEAD as well as the 1.6 branch to now silently
ignore messages written by Listeners while they are supposed to log
something else.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Avoiding logging loops

Posted by Ceki Gülcü <ce...@qos.ch>.
At 06:17 PM 1/11/2005, Stefan Bodewig wrote:
>Yes, I understand that - and I don't think we can really enforce it,
>at least not after we've had BuildListener not state that requirement
>for more than four years.

I don't think one can blame BuildListener for this. Even if the
requirement was clearly stated, Log4jListener would not have or could
not have done anything differently. It's a change in log4j not in Ant.


-- 
Ceki Gülcü

   The complete log4j manual: http://www.qos.ch/log4j/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Avoiding logging loops

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 11 Jan 2005, Ceki Gülc <ce...@qos.ch> wrote:

> I can't think of anything reasonable Log4jListener can do to prevent
> this or dance around it.

The only idea I came up with was temporarily re-setting System.out and
err.  Facing the choice between cholera and pestilence, I'd rather
silently ignore the recursive invocation than do that.

> The hypothesis of all listeners being able to avoid accessing the
> console from within the messageLogged(event) method is not verified
> in this case.

Yes, I understand that - and I don't think we can really enforce it,
at least not after we've had BuildListener not state that requirement
for more than four years.

> At this stage, log4j's behavior might seem quite strange but at
> least you should be aware that such eccentricity exists.

Absolutely, thanks for the heads-up.  We definitively need to deal
with it in some way or our own Log4jListener becomes useless.

Thanks

        Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Avoiding logging loops

Posted by Ceki Gülcü <ce...@qos.ch>.


At 05:02 PM 1/11/2005, Stefan Bodewig wrote:
>It might be better to state somewhere that BuildListeners are not
>allowed to create any output during messageLogged and keep the code as
>is - and modify Log4jListener which I've never looked into myself.
>
>Ceki, is there any way Log4jListener can avoid the output?  Probably
>not since it tries to pick the "correct" logger at runtime.

Hello Stefan,

Log4jListener tries to use the most suitable logger depending on the
contents of BuildEvent. When it has determined the most suitable
logger name, it invokes

  Logger.getLogger("most suitable name");

In log4j version 1.3alpha output on the console is generated
by every call to Logger.getLogger. I can't think of anything reasonable
Log4jListener can do to prevent this or dance around it. Moreover,
this idiosyncrasy might even survive, in one form or another, in
log4j 1.3final.

The hypothesis of all listeners being able to avoid accessing the
console from within the messageLogged(event) method is not verified in
this case. I understand your reluctance to change the code. At this
stage, log4j's behavior might seem quite strange but at least you
should be aware that such eccentricity exists.

Best regards,

>Stefan

-- 
Ceki Gülcü

   The complete log4j manual: http://www.qos.ch/log4j/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Avoiding logging loops

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 10 Jan 2005, Antoine Levy-Lambert <an...@gmx.de> wrote:

> I have not had the time to check your suggested code modification,
> but it makes sense to avoid these infinite loops.
> 
> What do other ant committers think ?

It might be better to state somewhere that BuildListeners are not
allowed to create any output during messageLogged and keep the code as
is - and modify Log4jListener which I've never looked into myself.

Ceki, is there any way Log4jListener can avoid the output?  Probably
not since it tries to pick the "correct" logger at runtime.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Avoiding logging loops

Posted by Ceki Gülcü <ce...@qos.ch>.
Hello Antoine,

Thank you for the quick response.

To be precise, the current code also avoids infinite loops except that
it treats recursion as an impossible event and throws an
exception. The proposed change also avoids infinite loops but by
ignoring recursive calls to Project.fireMessageLoggedEvent(), not by
throwing an exception.


At 10:25 PM 1/10/2005, Antoine Levy-Lambert wrote:
>Hello Ceki,
>
>I have not had the time to check your suggested code modification, but it 
>makes sense to avoid these infinite loops.
>
>What do other ant committers think ?
>
>(I have moved the discussion to dev@ant, I think this is more appropriate).
>
>Antoine

-- 
Ceki Gülcü

   The complete log4j manual: http://www.qos.ch/log4j/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org