作为 Windows 服务运行时的 Tomcat 日志记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1508711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat Logging while running as a windows service
提问by FacilityDerek
I have a web application running under Tomcat.
我有一个在 Tomcat 下运行的 Web 应用程序。
Logging for various features is implemented using java.util.logging.
各种功能的日志记录是使用 java.util.logging 实现的。
When running tomcat via startup.bat the logging files are created and record the logging as expected.
当通过 startup.bat 运行 tomcat 时,会创建日志文件并按预期记录日志。
When running as a windows service using the same war file the output from logging is virtually absent. There is some ( Barely any ) log output in stdout.log and stderr.log but not what is expected.
当使用相同的 war 文件作为 Windows 服务运行时,日志记录的输出几乎不存在。stdout.log 和 stderr.log 中有一些(几乎没有)日志输出,但不是预期的。
Does this sound familiar to anyone? what steps did you take to correct it?
这对任何人来说听起来都很熟悉吗?你采取了什么步骤来纠正它?
Regards
问候
采纳答案by FacilityDerek
As it turns out this is a configuration problem.
事实证明这是一个配置问题。
When started from the startup.bat tomcat will reference the logging.properties in the conf directory.
当从 startup.bat 启动时,tomcat 将引用 conf 目录中的 logging.properties。
When started as a service the jdk/jre/lib logging.properties comes into play.
当作为服务启动时,jdk/jre/lib logging.properties 开始发挥作用。
When running as a windows service, all console output is redirected to stdout.log in the tomcat logs directory .
作为 Windows 服务运行时,所有控制台输出都重定向到 tomcat 日志目录中的 stdout.log。
Attempts to capture logging in custom files with custom logging.properties files have so far failed.
迄今为止,尝试使用自定义 logging.properties 文件捕获自定义文件中的日志记录失败。
回答by kgiannakakis
stdout and stderr log files should have been created in the logs directory of your Tomcat installation.
stdout 和 stderr 日志文件应该已在 Tomcat 安装的日志目录中创建。
To configure logging use the "Configure Tomcat" application. You can set the error level and the location of the log files there.
要配置日志记录,请使用“配置 Tomcat”应用程序。您可以在那里设置错误级别和日志文件的位置。
回答by Aaron Digulla
Make sure that the Tomcat environment is the same in both cases. Check the paths and settings in the Tomcat service editor. Don't use the standard Windows properties dialog for services but start tomcat.exe with //ES//name
where name
is the name of the service.
确保 Tomcat 环境在两种情况下都相同。检查 Tomcat 服务编辑器中的路径和设置。不要使用标准的Windows属性对话框的服务,但开始tomcat.exe与//ES//name
那里name
是服务的名称。
回答by B5A7
When tomcat is started as a service, its default logging configuration actually overrides any application-specific logging configuration. As Aaron suggested the best way to set the configuration is using tomcatw //ES//tomcat_service_name, e.g. tomcat_service_name could be Tomcat5 depending on your installation preferences (also, use tomcatw, not tomcat - both executables can be found in C:\Program Files\Apache Software Foundation\Tomcat 5.0\bin). This postexplains how you can ensure that you use the correct service name (if there are no values in the dialog then the name is probably incorrect).
当 tomcat 作为服务启动时,它的默认日志配置实际上会覆盖任何特定于应用程序的日志配置。由于 Aaron 建议设置配置的最佳方法是使用 tomcatw //ES//tomcat_service_name,例如,根据您的安装首选项,tomcat_service_name 可以是 Tomcat5(另外,使用 tomcatw,而不是 tomcat - 两个可执行文件都可以在 C:\Program Files 中找到\Apache 软件基金会\Tomcat 5.0\bin)。这篇文章解释了如何确保使用正确的服务名称(如果对话框中没有值,则该名称可能不正确)。
I would post an image but I do not have sufficient rep. On the Java VM tab, enter the configuration in Java Options, e.g. -Dlog4j.configuration=service.log4j.properties
我会发布一张图片,但我没有足够的代表。在 Java VM 选项卡上,在 Java Options 中输入配置,例如 -Dlog4j.configuration=service.log4j.properties
The file that contains your logging configuration can then be placed in tomcat server classes directory, e.g. C:\Program Files\Apache Software Foundation\Tomcat 5.0\server\classes.
然后可以将包含日志配置的文件放在 tomcat 服务器类目录中,例如 C:\Program Files\Apache Software Foundation\Tomcat 5.0\server\classes。
There are several places where you can put the logging configuration file. I initially tried specifying a full path for the logging configuration file but log4j appears to check only certain paths. As this poststates, place -Dlog4j.debug as the first line in Java Options and you can debug what log4j is doing. The server classes directory is listed as one possible search path.
有几个地方可以放置日志配置文件。我最初尝试为日志记录配置文件指定完整路径,但 log4j 似乎只检查某些路径。正如这篇文章所述,将 -Dlog4j.debug 作为 Java 选项中的第一行,您可以调试 log4j 正在做什么。服务器类目录被列为一种可能的搜索路径。
When creating your log4j.properties file, name it something other than log4j.properties, e.g. service.log4j.properties. Naming it log4j.properties runs the risk that an application-specific log4j.properties file could be found, which would override your configuration but, which would then be subsequently ignored by the tomcat service.
创建 log4j.properties 文件时,将其命名为 log4j.properties 以外的其他名称,例如 service.log4j.properties。将其命名为 log4j.properties 存在可能会找到特定于应用程序的 log4j.properties 文件的风险,该文件会覆盖您的配置,但随后将被 tomcat 服务忽略。