2010-11-07 187 views
60

我想在tomcat中設置級別日誌記錄到DEBUG,但是在控制檯中只有INFO和WARN輸出。 有人可以告訴我什麼是錯的?如何在Tomcat中將級別日誌記錄設置爲DEBUG?

我的C:\ Tomcat的\ logging.properties:

# Licensed to the Apache Software Foundation (ASF) under one or more 
# contributor license agreements. See the NOTICE file distributed with 
# this work for additional DEBUGrmation regarding copyright ownership. 
# The ASF licenses this file to You under the Apache License, Version 2.0 
# (the "License"); you may not use this file except in compliance with 
# the License. You may obtain a copy of the License at 
# 
#  http://www.apache.org/licenses/LICENSE-2.0 
# 
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 

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

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

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

1catalina.org.apache.juli.FileHandler.level = DEBUG 
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 
1catalina.org.apache.juli.FileHandler.prefix = catalina. 

2localhost.org.apache.juli.FileHandler.level = DEBUG 
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 
2localhost.org.apache.juli.FileHandler.prefix = localhost. 

3manager.org.apache.juli.FileHandler.level = DEBUG 
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 
3manager.org.apache.juli.FileHandler.prefix = manager. 

4host-manager.org.apache.juli.FileHandler.level = DEBUG 
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 
4host-manager.org.apache.juli.FileHandler.prefix = host-manager. 

java.util.logging.ConsoleHandler.level = DEBUG 
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 = DEBUG 
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler 

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

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = DEBUG 
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.FileHandler 

# For example, set the com.xyz.foo logger to only log SEVERE 
# messages: 
#org.apache.catalina.startup.ContextConfig.level = DEBUG 
#org.apache.catalina.startup.HostConfig.level = DEBUG 
#org.apache.catalina.session.ManagerBase.level = DEBUG 
#org.apache.catalina.core.AprLifecycleListener.level=DEBUG 

我的日誌的例子:

INFO: Deploying configuration descriptor manager.xml 
08.11.2010 1:06:42 org.apache.catalina.startup.HostConfig deployWAR 
INFO: Deploying web application archive spring-mvc-trial.war 
08.11.2010 1:06:46 org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory docs 
08.11.2010 1:06:46 org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory examples 
08.11.2010 1:06:46 org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory ROOT 
08.11.2010 1:06:46 org.apache.coyote.http11.Http11AprProtocol start 
INFO: Starting Coyote HTTP/1.1 on http-8080 
08.11.2010 1:06:46 org.apache.coyote.ajp.AjpAprProtocol start 
INFO: Starting Coyote AJP/1.3 on ajp-8009 
08.11.2010 1:06:46 org.apache.catalina.startup.Catalina start 
INFO: Server startup in 3777 ms 
08.11.2010 1:09:36 org.apache.coyote.http11.Http11AprProtocol pause 
INFO: Pausing Coyote HTTP/1.1 on http-8080 
08.11.2010 1:09:36 org.apache.coyote.ajp.AjpAprProtocol pause 
INFO: Pausing Coyote AJP/1.3 on ajp-8009 
08.11.2010 1:09:37 org.apache.catalina.core.StandardService stop 
INFO: Stopping service Catalina 
08.11.2010 1:09:37 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 
SEVERE: The web application [/spring-mvc-trial] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
08.11.2010 1:09:37 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 
SEVERE: The web application [/spring-mvc-trial] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak. 
08.11.2010 1:09:38 org.apache.coyote.http11.Http11AprProtocol destroy 
INFO: Stopping Coyote HTTP/1.1 on http-8080 
08.11.2010 1:09:38 org.apache.coyote.ajp.AjpAprProtocol destroy 
INFO: Stopping Coyote AJP/1.3 on ajp-8009 
+0

對於Tomcat 8,請參閱:[Tomcat的8啓用調試日誌記錄列出不需要的罐子](http://stackoverflow.com/q/24821865/55075) – kenorb 2015-04-09 18:13:17

回答

57

首先,使用級別名稱爲FINE,不DEBUG。假設一分鐘即DEBUG實際上是有效的,因爲它使下面的解釋讓更多的感覺......

Handler specific properties部分,你對這些處理的日誌記錄級別設置爲DEBUG。這意味着處理程序將處理任何具有DEBUG級別或更高級別的日誌消息。這並不意味着任何DEBUG消息實際上都會傳遞給處理程序。

Facility specific properties部分,您將幾個明確指定的記錄器的記錄級別設置爲DEBUG。對於那些伐木者,任何級別爲DEBUG或以上的傳遞給處理程序。

默認日誌記錄級別爲INFO,除了Facility specific properties部分中提到的日誌記錄程序外,所有日誌記錄程序都具有該級別。

如果你想看到所有FINE信息,補充一點:

.level = FINE 

但是,這會生成日誌消息的一個巨大的數量。這可能更有用日誌記錄級別設置爲您的代碼:

your.package.level = FINE 

Tomcat 6/Tomcat 7日誌文件以獲取更多信息。有顯示的示例logging.properties文件使用FINE而不是DEBUG

... 
1catalina.org.apache.juli.FileHandler.level = FINE 
... 

,也爲您提供了額外的設置日誌級別的示例:

# For example, set the com.xyz.foo logger to only log SEVERE 
# messages: 
#org.apache.catalina.startup.ContextConfig.level = FINE 
#org.apache.catalina.startup.HostConfig.level = FINE 
#org.apache.catalina.session.ManagerBase.level = FINE 
+0

它的工作原理!非常感謝理查德! – gennad 2010-11-09 05:19:26

相關問題