log4j 在 unix 中记录到 catalina.out 而不是日志文件
在我的 Web 应用程序中,我通过在启动时加载的 servlet 中使用 PropertyConfigurator.configure(filepath)
函数来初始化 Web 应用程序中的日志记录。
String log4jfile = getInitParameter("log4j-init-file");
if (log4jfile != null) {
String propfile = getServletContext().getRealPath(log4jfile);
PropertyConfigurator.configure(propfile);
我已将 log4j.properties 文件放置在 WEB_INF/classes 目录中,并将该文件指定为
log4j.appender.rollingFile.File=${catalina.home}/logs/myapp.log
我的根记录器最初配置为:(
log4j.rootLogger=DEBUG, rollingFile,console
我相信控制台属性还记录了语句到 catalina.out)
在 Windows 中,日志记录似乎正常发生在日志文件中出现的语句中。
在 unix 中,我的日志语句被重定向到 catalina.out 而不是我的实际日志文件(其中仅包含来自初始化 servlet 的日志)。 所有后续日志都显示在 catalina.out 中。
这让我相信我的 log4j 没有正确设置,但我无法找出原因。 谁能帮我找出问题可能出在哪里。
提前致谢, 跌倒
In my web application I am inititalizing logging in my web application by using the PropertyConfigurator.configure(filepath)
function in a servlet which is loaded on startup.
String log4jfile = getInitParameter("log4j-init-file");
if (log4jfile != null) {
String propfile = getServletContext().getRealPath(log4jfile);
PropertyConfigurator.configure(propfile);
I have placed my log4j.properties file in WEB_INF/classes directory and am specifying the file as
log4j.appender.rollingFile.File=${catalina.home}/logs/myapp.log
My root logger was initally configured as:
log4j.rootLogger=DEBUG, rollingFile,console
(I believe the console attribute also logs the statements into catalina.out)
In windows the logging seems to occor normally with the statements appearing in the log file.
In unix my logging statements are being redirected to the catalina.out instead of my actual log file(Which contains only logs from the initalization servlet). All subsequent logs show up in catalina.out.
This leads me to believe that my log4j is not getting set properly but I am unable to figure out the cause. Could anyone help me figure out where the problem might be.
Thanks in advance,
Fell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这取决于您使用的服务器。
是汤姆猫吗? Windows 和 Linux 上的版本是否相同?
It will depend on the server you are using.
Is it Tomcat? Is it the same version on Windows and on Linux?
检查您的机器是否设置了CATALINA_HOME环境变量。
您可以在 Linux 中输入“echo $CATALINA_HOME”来检查它。
Check whether you have set CATALINA_HOME environmental variable in your machine.
You can check it in linux by typing 'echo $CATALINA_HOME'.
可能是权限问题 - 检查 ${catalina.home}/logs 目录的所有者和权限。
It may be a permissions problem - check the owners and permissions of the ${catalina.home}/logs directory.