简体   繁体   English

在UNIX中将log4j记录到catalina.out而不是日志文件中

[英]log4j logging to catalina.out in unix instead of log file

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. 在我的Web应用程序中,我通过在启动时加载的servlet中使用PropertyConfigurator.configure(filepath)函数来初始化在Web应用程序中的登录。

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.properties文件放置在WEB_INF / classes目录中,并将文件指定为

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) (我相信console属性还会将语句记录到catalina.out中)

In windows the logging seems to occor normally with the statements appearing in the log file. 在Windows中,日志记录似乎通常与日志文件中出现的语句一致。

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). 在unix中,我的日志记录语句被重定向到catalina.out而不是我的实际日志文件(其中仅包含来自初始化servlet的日志)。 All subsequent logs show up in catalina.out. 随后的所有日志都显示在catalina.out中。

This leads me to believe that my log4j is not getting set properly but I am unable to figure out the cause. 这使我相信我的log4j设置不正确,但是我无法找出原因。 Could anyone help me figure out where the problem might be. 谁能帮助我找出问题所在。

Thanks in advance, Fell 预先感谢,下跌

可能是权限问题-检查$ {catalina.home} / logs目录的所有者和权限。

It will depend on the server you are using. 这将取决于您使用的服务器。 Is it Tomcat? 是Tomcat吗? Is it the same version on Windows and on Linux? Windows和Linux上的版本是否相同?

Check whether you have set CATALINA_HOME environmental variable in your machine. 检查是否在计算机中设置了CATALINA_HOME环境变量。 You can check it in linux by typing 'echo $CATALINA_HOME'. 您可以在Linux中通过键入'echo $ CATALINA_HOME'进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM