我正在尝试调整Catalina的日志记录。我对Tomcat的logging.properties如下所示:
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler 1catalina.org.apache.juli.FileHandler.level = FINE 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.FileHandler.prefix = my-catalina. 1catalina.org.apache.juli.FileHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.SimpleFormatter.format=tomcat: [%1$tc] %4$s: %2$s - %5$s %6$s%n 2localhost.org.apache.juli.FileHandler.level = FINE 2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.FileHandler.prefix = localhost. 3manager.org.apache.juli.FileHandler.level = FINE 3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 3manager.org.apache.juli.FileHandler.prefix = manager. 4host-manager.org.apache.juli.FileHandler.level = FINE 4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 4host-manager.org.apache.juli.FileHandler.prefix = host-manager. 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 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.FileHandler
但是我无法使用格式化程序进行输出:
1catalina.org.apache.juli.FileHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.SimpleFormatter.format=tomcat: [%1$tc] %4$s: %2$s - %5$s %6$s%n
我进入的my-catalina.2018-03-16.log样子是:
my-catalina.2018-03-16.log
Mar 16, 2018 9:41:11 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 585 ms Mar 16, 2018 9:41:11 AM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina Mar 16, 2018 9:41:11 AM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.22
有什么想法吗?
但是我无法使用格式化程序进行输出
我认为您必须修改启动脚本,以便在SimpleFormatter加载类之前提供format属性。
SimpleFormatter
一旦加载了类,便会永久设置格式,因此,如果在读取日志记录属性之前加载了类,则将忽略您在文件中放置的内容。