Tomcat 应用程序显示“无法配置日志系统。未找到 log.properties。”

发布于 2024-08-08 22:52:34 字数 1113 浏览 1 评论 0原文

我有一个嵌入式 tomcat 应用程序,每当我启动它时,我都会看到这个错误两次打印到控制台:

Unable to configure the logging system.  No log.properties was found.

这看起来很愚蠢,但我已经做了一些谷歌搜索并搜索了 stackoverflow,似乎找不到遇到此问题的人。

我的主类大致如下所示:

public class AuthServerEntryPoint {
  static {
    org.apache.log4j.PropertyConfigurator.configure("conf/log4j.properties");
  }
public static void main(String[] args) {
  // ...
}

“conf/log4j.properties”包含看似有效的配置:

log4j.appender.mainAppend=org.apache.log4j.ConsoleAppender
log4j.appender.mainAppend.layout=org.apache.log4j.PatternLayout
log4j.appender.mainAppend.layout.ConversionPattern=%d %p [%t] %c -- %m%n 

log4j.appender.fileAppend=org.apache.log4j.FileAppender
log4j.appender.fileAppend.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppend.layout.ConversionPattern=%d %p [%t] %c - %m%n 
log4j.appender.fileAppend.file=logs/myservice.log

log4j.rootLogger = info, fileAppend
log4j.logger.com.mycompany.myservice = debug, fileAppend

并且日志记录实际上确实有效 - 即日志被正确写入 myservice.log。那么什么给出呢?

谢谢! -卡尔

I have an embedded tomcat app and whenever I start it up I see this error printed to the console twice:

Unable to configure the logging system.  No log.properties was found.

It seems stupid, but I've done some googling and searched stackoverflow and can't seem to find someone experiencing this problem.

My main class Looks roughly like this:

public class AuthServerEntryPoint {
  static {
    org.apache.log4j.PropertyConfigurator.configure("conf/log4j.properties");
  }
public static void main(String[] args) {
  // ...
}

"conf/log4j.properties" contains a seemingly valid configuration:

log4j.appender.mainAppend=org.apache.log4j.ConsoleAppender
log4j.appender.mainAppend.layout=org.apache.log4j.PatternLayout
log4j.appender.mainAppend.layout.ConversionPattern=%d %p [%t] %c -- %m%n 

log4j.appender.fileAppend=org.apache.log4j.FileAppender
log4j.appender.fileAppend.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppend.layout.ConversionPattern=%d %p [%t] %c - %m%n 
log4j.appender.fileAppend.file=logs/myservice.log

log4j.rootLogger = info, fileAppend
log4j.logger.com.mycompany.myservice = debug, fileAppend

And the logging actually does work - i.e., logs are correctly written to myservice.log. So what gives?

Thanks!
-Carl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空气里的味道 2024-08-15 22:52:34

嵌入式 Tomcat 应用程序是指您从 Java 代码启动 Tomcat 并使用 org.apache.catalina.startup.Embedded 类吗?

如果是,我的猜测是,在使用脚本时,Tomcat 可能无法找到在 catalina.sh (或等效文件)中设置的日志配置文件:

LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"

奇怪的是,该文件是称为 logging.properties,而不是 log.properties,所以我真的不确定。不过我没有检查 Tomcat 的来源,也许他们在那里做了某种黑魔法。

您能否尝试将 $CATALINA_BASE/conf/logging.properties 重命名为 log.properties (或不)并将其放在应用程序的类路径中(或设置-Djava.util.logging.config.file)?

By embedded Tomcat app, do you mean that you are starting Tomcat from Java code and are using the class org.apache.catalina.startup.Embedded?

If yes, my guess is that Tomcat might not be able to find its logging configuration file that is set up in catalina.sh (or equivalent) when using the scripts:

LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"

The odd part is that this file is called logging.properties, not log.properties, so I'm really not sure. I didn't check Tomcat sources though, maybe they are doing some kind of black magic in there.

Could you just try to rename $CATALINA_BASE/conf/logging.properties into log.properties (or not) and to put it on the classpath of your app (or to set -Djava.util.logging.config.file)?

情场扛把子 2024-08-15 22:52:34

默认情况下,log4j 将在类路径上查找日志记录属性文件。将您的 web 应用程序的日志记录属性配置文件放入其 WEB-INF/classes 目录中;例如,

$CATALINA_HOME/webapps/<yourApp>/WEB-INF/classes/log4j.properties

这是参考文档推荐的让 Web 应用程序使用 Log4j 的简单方法。这就是我自己用于 Web 应用程序日志记录的方法。

还有多种其他方法可以在 Tomcat 上配置 Log4j 日志记录。您的 Tomcat 可能已(部分)配置为使用其中之一,但某些事情尚未完成。

通过系统属性配置 Tomcat 的 log4j 日志记录是一个选项,可以避免弄清楚 log4j 正在查找的位置......以及出了什么问题。但随后您将不得不创建/使用自定义启动脚本,或者必须记住在启动 Tomcat 之前设置环境变量。

参考资料:

By default, log4j will look for a logging properties file on the classpath. Put your webapp's logging properties config file into its WEB-INF/classes directory; e.g.

$CATALINA_HOME/webapps/<yourApp>/WEB-INF/classes/log4j.properties

This is the simple approach to getting a webapp to use Log4j is recommended by the referenced documentation. And it is the approach I use myself for webapp logging.

There are various other ways to configure Log4j logging on Tomcat as well. It is possible that your Tomcat has been (partly) configured to use one of them, but something has not been done quite right.

Configuring Tomcat' log4j logging via the system properties is an option that avoids figuring out where log4j is looking ... and what is going wrong. But you are then stuck with creating/using a custom launch script or having to remember to set environment variables before launching Tomcat.

References:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文