在运行时配置 log4j
我正在使用 org.apache.tools.ant.listener.Log4jListener 来管理我的 ant 脚本的日志记录。 ant 脚本是高度可配置的,并且设计为使用不同的参数以不同的方式运行,因此我需要能够记录到运行时指定的文件。我有一个 log4j.properties ,它指定一个日志文件为 build.log ,尽管我尝试启动 ant 重新定义 log4j.properties 中定义的属性,但没有成功。
构建会忽略它们并继续写入 build.log。我还没有找到关于写入自定义文件的太多支持,除非它是在 Java 中的 Logger 类。
也许我的想法是错误的。 log4j.properties 的处理方式与 ant 脚本中的属性文件不同(因此可以从命令行覆盖)?有没有一种方法可以让我在不编写自定义任务或其他内容的情况下智能地完成此操作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用可以在命令行上动态定义的系统属性来设置 log4j.properties 文件。下面的属性是“${logfile.name}”。 log4j 配置示例如下:
调用“ant”时传递属性的命令行选项是“-Dlogfile.name={运行时路径/日志文件的文件名}”。将 {运行时路径/日志文件的文件名} 替换为您的文件名。当 ant 运行时,该值被设置为系统属性。然后,该系统属性会在运行时替换到 log4j.properties 中。
http://ant.apache.org/manual/running.html
You setup your log4j.properties file using a system property that you can define dynamically on the command line. The property below is "${logfile.name}". An example log4j configuration would be like this:
The command line option to pass a property, when calling "ant", is "-Dlogfile.name={runtime path/filename of log file}". Replace {runtime path/filename of log file} with your file name. When ant is run this value is set as a system property. That system property is then substituted into the log4j.properties at runtime.
http://ant.apache.org/manual/running.html