aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes using ant with Log4jListener - how do I filter out the task events Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "using ant with Log4jListener - how do I filter out the task events " Watch "using ant with Log4jListener - how do I filter out the task events " New topic
Author

using ant with Log4jListener - how do I filter out the task events

Matthew Knaus
Greenhorn

Joined: Jun 04, 2010
Posts: 3
Hi,

I am running ant from the command line with the following options:

$ant -listener org.apache.tools.ant.listener.Log4jListener

My log4j.properties file is as follows:

#
log4j.rootLogger=DEBUG, stdout
# direct messages to stout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.Threshold=error
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n

When I run the ant task, INFO events are output to the terminal:

INFO [main] (Log4jListener.java:63) - Build started.
INFO [main] (Log4jListener.java:118) - Task "property" started.
INFO [main] (Log4jListener.java:131) - Task "property" finished.
INFO [main] (Log4jListener.java:131) - Task "echo" finished.
INFO [main] (Log4jListener.java:118) - Task "java" started.
...

Is there a way I can filer these events?? Do I need to provide an option to ant or something?
javascript:emoticon('');







Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Matthew, welcome to Java Ranch!

I think you need to capitalize the threshold:

log4j.appender.stdout.Threshold=ERROR


JBoss In Action
Matthew Knaus
Greenhorn

Joined: Jun 04, 2010
Posts: 3
I believe it is case insensitive. I am using the jvmarg "-Dlog4j.debug=true", which displays the following output at runtime:


INFO [Thread-3] (Log4jListener.java:163) - log4j: Parsing appender named "stdout".
INFO [Thread-3] (Log4jListener.java:163) - log4j: Parsing layout options for "stdout".
INFO [Thread-3] (Log4jListener.java:163) - log4j: Setting property [conversionPattern] to [%m%n].
INFO [Thread-3] (Log4jListener.java:163) - log4j: End of parsing for "stdout".
INFO [Thread-3] (Log4jListener.java:163) - log4j: Setting property [target] to [System.out].
INFO [Thread-3] (Log4jListener.java:163) - log4j: Setting property [threshold] to [ERROR].
INFO [Thread-3] (Log4jListener.java:163) - log4j: Parsed "stdout" options.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

I am using the jvmarg "-Dlog4j.debug=true"

That explains it - if you are asking Log4J to debug its own code no wonder you are getting INFO output for Log4jListener.
Matthew Knaus
Greenhorn

Joined: Jun 04, 2010
Posts: 3
I figured out my problem and hope this can help someone else. I was unable to filter out the messages that are logged in Log4jListener when running ant with the following options:

$ant -listener org.apache.tools.ant.listener.Log4jListener

I added the jvmarg "-Dlog4j.debug=true" and noticed that several messages were output to the console before log4j was initialized! I found that you can configure log4j in build.xml instead of using the -listener command line option. I no longer get annoying info messages with this configuration.

My build.xml looks like:


Cheers!
- Matt


Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Thanks for sharing!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using ant with Log4jListener - how do I filter out the task events