结合 log4j 和 log4perl 日志
我有一个 Java 应用程序,它使用 Runtime.exec 启动 Perl 程序,等待它返回,然后继续。我希望 Java 应用程序的 log4j 输出和 Perl 程序的 log4perl 输出转到同一个文件。
在我的 log4j.properties 文件中,我有:
log4j.appender.app=org.apache.log4j.DailyRollingFileAppender log4j.appender.app.File=/path/app.log log4j.appender.app.DatePattern=.yyyy-MM-dd log4j.appender.app.Append=false log4j.appender.app.layout=org.apache.log4j.PatternLayout log4.appender.app.layout.ConversionPattern=%5p [%t] (%F:%L) %m%n
(我已将 Append 设置为 false,因为如果重新启动 Java 应用程序,我想覆盖同一天以前的任何日志文件。)
在 Perl 程序中,我有:
Log::Log4perl->easy_init({level => $DEBUG, 文件=> ">>/path/app.log"});
这会导致 log4j 输出,然后是 log4perl 输出,转到同一个文件,但是当 Perl 程序完成时,Java 应用程序无法显示不再写入文件。
我可以以某种方式重置 Java 端的文件句柄吗? 我可以以某种方式将记录器而不是文件名传递给 Perl 程序吗?
我想过将两者的输出发送到控制台,然后将其保存到文件中,但这对我来说会失去功能,因为我利用了将不同级别的输出发送到控制台和文件的优势。
I have a Java application that launches a Perl program using Runtime.exec, waits for it to return and then continues. I would like the log4j output from the Java application and the log4perl output from the Perl program to go to the same file.
In my log4j.properties file, I have:
log4j.appender.app=org.apache.log4j.DailyRollingFileAppender
log4j.appender.app.File=/path/app.log
log4j.appender.app.DatePattern=.yyyy-MM-dd
log4j.appender.app.Append=false
log4j.appender.app.layout=org.apache.log4j.PatternLayout
log4.appender.app.layout.ConversionPattern=%5p [%t] (%F:%L) %m%n
(I've set Append to false because if the Java application is relaunched, I want to overwrite any previous log file from the same day.)
In the Perl program, I have:
Log::Log4perl->easy_init({level => $DEBUG,
file => ">>/path/app.log"});
This results in the log4j output, followed by the log4perl output, going to the same file, but when the Perl program finishes, the Java application cannot seem to write to the file anymore.
Can I reset my file handle on the Java side somehow?
Can I somehow pass the logger to the Perl program instead of the filename?
I thought of sending output from both to the console and then saving that to a file, but that would be a loss of functionality for me since I'm taking advantage of sending different levels of output to the console and the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论