Tomcat7 日志记录地狱 - 为什么会出现两种不同的格式?
Tomcat7 logging hell - why two different formats coming out?
当我最初发布这个问题时,我在 Eclipse 中的 logging.properties
看起来像这样:
handlers = java.util.logging.ConsoleHandler
org.apache.catalina.core=OFF
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=JUL %4$s: %2$s%n%4$s: %5$s%n
我在具有此配置的 Linux 服务器上也遇到了同样的问题:
handlers = 2localhost.org.apache.juli.FileHandler, org.apache.juli.FileHandler
.handlers = org.apache.juli.FileHandler
2localhost.org.apache.juli.FileHandler.level = INFO
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
org.apache.juli.FileHandler.level = ALL
org.apache.juli.FileHandler.formatter = java.util.logging.SimpleFormatter
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
java.util.logging.SimpleFormatter.format=tomcat: %4$s: %2$s%n%4$s: %5$s%n
org.apache.catalina.handlers = org.apache.juli.FileHandler
org.apache.catalina.startup.level = SEVERE
org.apache.catalina.session.ManagerBase.level = SEVERE
org.apache.catalina.core.AprLifecycleListener.level=SEVERE
org.apache.catalina.connector.level = SEVERE
org.apache.coyote.level=SEVERE
org.apache.catalina.level=ALL
org.apache.catalina.startup.HostConfig.level = SEVERE
org.apache.catalina.loader.WebappClassLoader.level = SEVERE
org.apache.catalina.session.ManagerBase.level = INFO
# ServletContext logger
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = ALL
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].formatter = java.util.logging.SimpleFormatter
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].format=servlet: %4$s: %2$s%n%4$s: %5$s%n
为什么我在 Eclipse 中的控制台登录看起来像这样?
JUL INFO: org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_05\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;c:\Program Files (x86)\Intel\iCLS Client\;c:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files (x86)\MySQL\MySQL Utilities 1.4.3\;C:\Program Files (x86)\MySQL\MySQL Utilities 1.4.3\Doctrine extensions for PHP\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Git\cmd;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits.0\Windows Performance Toolkit\;C:\Program Files (x86)\BaseX\bin;C:\Program Files (x86)\WinMerge;C:\Program Files (x86)\Skype\Phone\;.
JUL WARNING: org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ctc_web_front_ui' did not find a matching property.
JUL INFO: org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
JUL INFO: org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
JUL INFO: org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 359 ms
JUL INFO: org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
JUL INFO: org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
JUL INFO: org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
JUL INFO: org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'servletSpringDispatcher'
JUL INFO: org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'servletSpringDispatcher': initialization started
Bare INFO 消息来自哪里?
为什么 catalina.core 消息仍然显示,即使我将它们设置为关闭?
在 Linux 服务器上,JULI 日志如下所示:
tomcat: FINE: org.apache.catalina.core.ContainerBase addChildInternal
FINE: Add child StandardHost[localhost] StandardEngine[Catalina]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardServer[8005]] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [org.apache.catalina.deploy.NamingResources@13fee20c] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [org.apache.catalina.deploy.NamingResources@13fee20c] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardService[Catalina]] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardEngine[Catalina]] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardEngine[Catalina]] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [Connector[HTTP/1.1-8080]] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [org.apache.catalina.connector.MapperListener@737996a0] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [org.apache.catalina.connector.MapperListener@737996a0] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [Connector[HTTP/1.1-8080]] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardService[Catalina]] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardServer[8005]] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardServer[8005]] to [STARTING_PREP]
tomcat: FINE: org.apache.catalina.core.NamingContextListener lifecycleEvent
FINE: Bound StandardServer[8005]
tomcat: FINE: org.apache.catalina.core.NamingContextListener createNamingContext
FINE: Creating JNDI naming context
tomcat: FINE: org.apache.catalina.core.NamingContextListener addResource
同样的问题,为什么不是所有行都以 tomcat:
开头?
更新
在调试时我发现每个日志条目的两行都来自 java.util.logging.Logger.logp()
我认为您缺少 jul-to-slf4j。详情请看这里slf4j legacy bridge documentation
您所指的信息消息实际上并不是核心的一部分。它们由 类 在不同的包中生成。通过剖析 catalina 库并识别负责特定日志的 类,这里是阻止登录 tomcat 7.0.63
的配置,方法是附加到默认值 logging.properties
:
org.apache.catalina.startup.level=OFF
org.apache.catalina.startup.handlers=1catalina.org.apache.juli.FileHandler.level
org.apache.catalina.core.level=OFF
org.apache.catalina.core.handlers=1catalina.org.apache.juli.FileHandler.level
org.apache.coyote.level=OFF
org.apache.coyote.handlers=1catalina.org.apache.juli.FileHandler.level
My logging.properties in Eclipse
我不知道你的工作区是如何配置的。也许那个文件根本没有被使用。
Java 日志记录由系统属性配置。
您需要一个 属性 (-Djava.util.logging.manager
) 来将 org.apache.juli.ClassLoaderLogManager
配置为 Java 日志记录的日志管理器实现。
您需要其他 属性 (-Djava.util.logging.config.file
) 来配置配置文件的路径。
通常这两个属性都由启动脚本(catalina.sh
、catalina.bat
)设置,但 Eclipse 直接启动 java,没有该脚本的帮助,因此这些系统属性具有在启动配置中明确设置。
Tomcat JULI 支持按类加载器配置日志记录。
此功能允许通过打包 WEB-INF/classes/logging.properties
文件为每个 Web 应用程序单独配置日志记录。
如果您意外地将 logging.properties
文件放入类路径,它会产生相同的效果:它将取代由该类加载器加载的 类 的默认配置。
例如众所周知,某些版本的 Jollyday 库(4 年前)包含一个意外的 logging.properties
文件,该文件启用了 FINE 日志记录。
.level = ALL
从发帖顶部开始,答案就在眼前:
java.util.logging.SimpleFormatter.format=JUL %4$s: %2$s%n%4$s: %5$s%n
^^^^^^^
格式字符串中的额外 %n%4$s:
是导致显示附加行的原因。呸
当我最初发布这个问题时,我在 Eclipse 中的 logging.properties
看起来像这样:
handlers = java.util.logging.ConsoleHandler
org.apache.catalina.core=OFF
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=JUL %4$s: %2$s%n%4$s: %5$s%n
我在具有此配置的 Linux 服务器上也遇到了同样的问题:
handlers = 2localhost.org.apache.juli.FileHandler, org.apache.juli.FileHandler
.handlers = org.apache.juli.FileHandler
2localhost.org.apache.juli.FileHandler.level = INFO
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
org.apache.juli.FileHandler.level = ALL
org.apache.juli.FileHandler.formatter = java.util.logging.SimpleFormatter
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
java.util.logging.SimpleFormatter.format=tomcat: %4$s: %2$s%n%4$s: %5$s%n
org.apache.catalina.handlers = org.apache.juli.FileHandler
org.apache.catalina.startup.level = SEVERE
org.apache.catalina.session.ManagerBase.level = SEVERE
org.apache.catalina.core.AprLifecycleListener.level=SEVERE
org.apache.catalina.connector.level = SEVERE
org.apache.coyote.level=SEVERE
org.apache.catalina.level=ALL
org.apache.catalina.startup.HostConfig.level = SEVERE
org.apache.catalina.loader.WebappClassLoader.level = SEVERE
org.apache.catalina.session.ManagerBase.level = INFO
# ServletContext logger
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = ALL
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].formatter = java.util.logging.SimpleFormatter
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].format=servlet: %4$s: %2$s%n%4$s: %5$s%n
为什么我在 Eclipse 中的控制台登录看起来像这样?
JUL INFO: org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_05\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;c:\Program Files (x86)\Intel\iCLS Client\;c:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files (x86)\MySQL\MySQL Utilities 1.4.3\;C:\Program Files (x86)\MySQL\MySQL Utilities 1.4.3\Doctrine extensions for PHP\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Git\cmd;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits.0\Windows Performance Toolkit\;C:\Program Files (x86)\BaseX\bin;C:\Program Files (x86)\WinMerge;C:\Program Files (x86)\Skype\Phone\;.
JUL WARNING: org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ctc_web_front_ui' did not find a matching property.
JUL INFO: org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
JUL INFO: org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
JUL INFO: org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 359 ms
JUL INFO: org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
JUL INFO: org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
JUL INFO: org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
JUL INFO: org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'servletSpringDispatcher'
JUL INFO: org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'servletSpringDispatcher': initialization started
Bare INFO 消息来自哪里?
为什么 catalina.core 消息仍然显示,即使我将它们设置为关闭?
在 Linux 服务器上,JULI 日志如下所示:
tomcat: FINE: org.apache.catalina.core.ContainerBase addChildInternal
FINE: Add child StandardHost[localhost] StandardEngine[Catalina]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardServer[8005]] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [org.apache.catalina.deploy.NamingResources@13fee20c] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [org.apache.catalina.deploy.NamingResources@13fee20c] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardService[Catalina]] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardEngine[Catalina]] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardEngine[Catalina]] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [Connector[HTTP/1.1-8080]] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [org.apache.catalina.connector.MapperListener@737996a0] to [INITIALIZING]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [org.apache.catalina.connector.MapperListener@737996a0] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [Connector[HTTP/1.1-8080]] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardService[Catalina]] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardServer[8005]] to [INITIALIZED]
tomcat: FINE: org.apache.catalina.util.LifecycleBase setStateInternal
FINE: Setting state for [StandardServer[8005]] to [STARTING_PREP]
tomcat: FINE: org.apache.catalina.core.NamingContextListener lifecycleEvent
FINE: Bound StandardServer[8005]
tomcat: FINE: org.apache.catalina.core.NamingContextListener createNamingContext
FINE: Creating JNDI naming context
tomcat: FINE: org.apache.catalina.core.NamingContextListener addResource
同样的问题,为什么不是所有行都以 tomcat:
开头?
更新
在调试时我发现每个日志条目的两行都来自 java.util.logging.Logger.logp()
我认为您缺少 jul-to-slf4j。详情请看这里slf4j legacy bridge documentation
您所指的信息消息实际上并不是核心的一部分。它们由 类 在不同的包中生成。通过剖析 catalina 库并识别负责特定日志的 类,这里是阻止登录 tomcat 7.0.63
的配置,方法是附加到默认值 logging.properties
:
org.apache.catalina.startup.level=OFF
org.apache.catalina.startup.handlers=1catalina.org.apache.juli.FileHandler.level
org.apache.catalina.core.level=OFF
org.apache.catalina.core.handlers=1catalina.org.apache.juli.FileHandler.level
org.apache.coyote.level=OFF
org.apache.coyote.handlers=1catalina.org.apache.juli.FileHandler.level
My logging.properties in Eclipse
我不知道你的工作区是如何配置的。也许那个文件根本没有被使用。
Java 日志记录由系统属性配置。
您需要一个 属性 (
-Djava.util.logging.manager
) 来将org.apache.juli.ClassLoaderLogManager
配置为 Java 日志记录的日志管理器实现。您需要其他 属性 (
-Djava.util.logging.config.file
) 来配置配置文件的路径。通常这两个属性都由启动脚本(
catalina.sh
、catalina.bat
)设置,但 Eclipse 直接启动 java,没有该脚本的帮助,因此这些系统属性具有在启动配置中明确设置。Tomcat JULI 支持按类加载器配置日志记录。
此功能允许通过打包
WEB-INF/classes/logging.properties
文件为每个 Web 应用程序单独配置日志记录。如果您意外地将
logging.properties
文件放入类路径,它会产生相同的效果:它将取代由该类加载器加载的 类 的默认配置。例如众所周知,某些版本的 Jollyday 库(4 年前)包含一个意外的
logging.properties
文件,该文件启用了 FINE 日志记录。.level = ALL
从发帖顶部开始,答案就在眼前:
java.util.logging.SimpleFormatter.format=JUL %4$s: %2$s%n%4$s: %5$s%n
^^^^^^^
格式字符串中的额外 %n%4$s:
是导致显示附加行的原因。呸