简体   繁体   English

无法使 tomcat-maven-plugin 创建日志文件?

[英]Can't make tomcat-maven-plugin create a log file?

I am running the mvn tomcat:run-war target, and get a directory structure that has a logs directory.我正在运行 mvn tomcat:run-war 目标,并获得一个包含日志目录的目录结构。 But alas, no log.但可惜,没有日志。 I would just replace this with log4j logging, but this has proven difficult for a variety of reasons.我只想用 log4j 日志记录替换它,但由于各种原因,这已被证明是困难的。

I have tried explicitly setting the log file configuration.我曾尝试明确设置日志文件配置。 My pom.xml definition currently looks like:我的 pom.xml 定义目前看起来像:

 <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>tomcat-maven-plugin</artifactId>
            <configuration>
                <port>8084</port>
                <systemProperties>
                     <java.util.logging.config.file>${basedir}/src/main/webapp/WEB-INF/logging.properties</java.util.logging.config.file>
                </systemProperties>
            </configuration>
            <version>1.1</version>
  </plugin>

I see during startup that the property is being read.我在启动期间看到正在读取该属性。 My properties file is below;我的属性文件在下面; I am dumping things to /tmp just to be sure I know where to look.我将东西倾倒到 /tmp 只是为了确保我知道在哪里看。

handlers = 1catalina.org.apache.juli.FileHandler, \
           2localhost.org.apache.juli.FileHandler, \
           3manager.org.apache.juli.FileHandler, \
           java.util.logging.ConsoleHandler

.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################    

1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = /tmp/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.

2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = /tmp/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.

3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = /tmp/logs
3manager.org.apache.juli.FileHandler.prefix = manager.
3manager.org.apache.juli.FileHandler.bufferSize = 16384

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter


############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = \
   2localhost.org.apache.juli.FileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = \
   3manager.org.apache.juli.FileHandler

I would be really grateful if anyone had any thoughts.如果有人有任何想法,我将不胜感激。

I've just been through a similar process, not entirely successfully...我刚刚经历过类似的过程,并不完全成功......

The first thing to note is that you need to be clear if you want to change the logging configuration for your web application, or for Tomcat itself.首先要注意的是,如果要更改 Web 应用程序或 Tomcat 本身的日志记录配置,则需要明确。 See logging documentation on the Tomcat website for some details - in particular:有关详细信息,请参阅Tomcat 网站上的日志记录文档- 特别是:

This means that logging can be configured at the following layers:这意味着可以在以下层配置日志记录:

  • Globally.全球。 That is usually done in the ${catalina.base}/conf/logging.properties file.这通常在 ${catalina.base}/conf/logging.properties 文件中完成。 The file is specified by the java.util.logging.config.file System property which is set by the startup scripts.该文件由 java.util.logging.config.file 系统属性指定,该属性由启动脚本设置。 If it is not readable or is not configured, the default is to use the ${java.home}/lib/logging.properties file in the JRE.如果不可读或未配置,则默认使用 JRE 中的 ${java.home}/lib/logging.properties 文件。
  • In the web application.在 Web 应用程序中。 The file will be WEB-INF/classes/logging.properties该文件将是 WEB-INF/classes/logging.properties

Having done this I am able reconfigure my application's logging, when deployed to a standalone Tomcat server.完成此操作后,当部署到独立的 Tomcat 服务器时,我能够重新配置我的应用程序的日志记录。 However I was unable to get this to work with the Maven Tomcat plugin - I then discovered that somebody had filed bug MTOMCAT-127 which at the time of writing is unresolved, and would seem to describe what I've been seeing.但是我无法让它与 Maven Tomcat 插件一起工作 - 然后我发现有人提交了错误 MTOMCAT-127 ,在撰写本文时尚未解决,并且似乎描述了我所看到的。

So not entirely successful - but I hope I can come back and update this answer once the MTOMCAT-127 issue has progressed...所以并不完全成功 - 但我希望一旦 MTOMCAT-127 问题取得进展,我可以回来更新这个答案......

It's not really a tomcat plugin bug, what happens is if you choose the java api logging for the tomcat maven plugin you should know that there is a maven core library that also uses the java api logging called sisu-guice- 3.2.3-no_aop.jar (class is com.google.inject.internal.util.Stopwatch).这不是真正的tomcat插件错误,如果您为tomcat maven插件选择java api日志记录,您应该知道有一个maven核心库也使用名为sisu-guice-3.2.3-no_aop的java api日志记录.jar(类是 com.google.inject.internal.util.Stopwatch)。 This library instantiates the LogManager with the default values ​​of the VM (INFO, etc) but not with the class that Tomcat needs to write its logs org.apache.juli.ClassLoaderLogManager.该库使用VM的默认值(INFO等)实例化LogManager,但不使用Tomcat编写其日志所需的类org.apache.juli.ClassLoaderLogManager。 This class has an attribute called manager which is of type class, not instance.这个类有一个名为 manager 的属性,它是类类型,而不是实例。 If we want to modify it, we must restart the VM but the Maven library sisu-guice-3.2.3-no_aop.jar will overwrite the LogManager and the RootLogger again.如果我们想修改它,我们必须重新启动VM,但是Maven库sisu-guice-3.2.3-no_aop.jar会再次覆盖LogManager和RootLogger。

Regarding the comment:关于评论:

mvn tomcat7: run -Djava.util.logging.config.file = src / main / webapp / WEB-INF / classes / logging.properties mvn tomcat7: run -Djava.util.logging.config.file = src / main / webapp / WEB-INF / classes / logging.properties

This is incorrect since this property is going to be set when the LogManager has already been instantiated.这是不正确的,因为将在 LogManager 已经实例化时设置此属性。

One solution is to copy the mvn.bat to your working directory, but you have to edit it, adding to the classpath the dependency tomcat-embed-logging-juli-7.0.47.jar and the directory where you will keep your logging.properties with this already works that the SystemClassLoader will start it sooner.一种解决方案是将 mvn.bat 复制到您的工作目录,但您必须对其进行编辑,将依赖项 tomcat-embed-logging-juli-7.0.47.jar 和您将保留日志记录的目录添加到类路径中。具有此功能的属性已经可以工作,SystemClassLoader 将更快地启动它。

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

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