Configuring log4j at runtime

Posted by Neil on Stack Overflow See other posts from Stack Overflow or by Neil
Published on 2010-12-29T14:49:33Z Indexed on 2010/12/29 14:54 UTC
Read the original article Hit count: 171

Filed under:
|

I'm using org.apache.tools.ant.listener.Log4jListener to manage logging with my ant script. The ant script is highly configurable and designed to be run different ways with different parameters and therefore I need to be able to log to files specified at runtime. I have a log4j.properties which specifies a log file to be build.log, and despite my attempts to launch ant redefining properties defined in log4j.properties have been unsuccessful.

The build ignores them and continues to write to build.log. I haven't found much support regarding writing to custom files unless it's in Java with their Logger class.

Perhaps I'm thinking this through wrong. log4j.properties isn't treated in the same way as a property file in an ant script (hence overrideable from the command line)? Is there a way I can do this intelligently without writing a custom task or something?

© Stack Overflow or respective owner

Related posts about ant

Related posts about log4j