2013-08-06 72 views
0

我有一個在Google App Engine(GAE)v1.8.2上運行的應用程序。我一直在使用java.util.logging。我的類有記錄器定義爲:關閉Google App Engine應用程序中的控制檯日誌記錄

private static final Logger logger = Logger.getLogger(MyClass.class.getName());

我的AppEngine-web.xml中有這些行:

<!-- Configure java.util.logging --> 
    <system-properties> 
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> 
    </system-properties> 

的logging.properties文件包含這些行:

# A default java.util.logging configuration. 
# (All App Engine logging is through java.util.logging by default). 
# 
# To use this configuration, copy it into your application's WEB-INF 
# folder and add the following to your appengine-web.xml: 
# 
# <system-properties> 
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> 
# </system-properties> 
# WARNING , INFO, SEVERE, OFF 
handlers=java.util.logging.ConsoleHandler 
# Set the default logging level for all loggers to WARNING 
.level = OFF 
java.util.logging.ConsoleHandler.level=OFF 
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 

但是,我還是繼續看INFO從我的代碼登錄在瀏覽器控制檯中。如何關閉完全註銷的控制檯?

更新:

# Logging configuration file for Google App Engine tools. 

# Specify the handlers to create in the root logger 
# (all loggers are children of the root logger) 
# The following creates the console handler 
handlers = java.util.logging.ConsoleHandler 

# Set the default logging level for the root logger 
.level = INFO 

# Set the default logging level for the datanucleus loggers 
DataNucleus.JDO.level=WARNING 
DataNucleus.Persistence.level=WARNING 
DataNucleus.Cache.level=WARNING 
DataNucleus.MetaData.level=WARNING 
DataNucleus.General.level=WARNING 
DataNucleus.Utility.level=WARNING 
DataNucleus.Transaction.level=WARNING 
DataNucleus.Datastore.level=WARNING 
DataNucleus.ClassLoading.level=WARNING 
DataNucleus.Plugin.level=WARNING 
DataNucleus.ValueGeneration.level=WARNING 
DataNucleus.Enhancer.level=WARNING 
DataNucleus.SchemaTool.level=WARNING 

# FinalizableReferenceQueue tries to spin up a thread and fails. This 
# is inconsequential, so don't scare the user. 
com.google.common.base.FinalizableReferenceQueue.level=WARNING 
com.google.appengine.repackaged.com.google.common.base.FinalizableReferenceQueue.level=WARNING 

# We assume that people will generally want to see this message, even 
# if they override the root level to WARNING. If they really want to 
# turn it off, they can always override this level as well. 
com.google.appengine.tools.development.DevAppServerImpl.level=INFO 

感謝:我的AppEngine上的Java-SDK-1.8.2 /配置/ SDK/logging.properties文件的內容。

回答

0

您應該確認LogManager正在使用您的logging.properties。一種簡單的測試方法是將ConsoleHandler格式化程序從java.util.logging.SimpleFormatter更改爲java.util.logging.XMLFormatter,然後查看您的輸出是否爲xml。如果是xml,那麼你可以嘗試註釋掉handlers=這一行。如果輸出仍然是從SimpleFormatter那麼:

  1. 檢查logging.properties的路徑。
  2. 確保SecurityManager未阻止對記錄進行更改。
  3. 編寫代碼以遍歷所有記錄器並輸出所有附加處理器的類名。然後更新您的logging.properties以禁用可能正在寫入控制檯的任何其他處理程序。
  4. 編寫代碼以遍歷所有記錄器和禁用以及所有控制檯處理程序。
  5. System.out.close(); System.err.close();
  6. new FileOutputStream(FileDescriptor.out).close();新的FileOutputStream(FileDescriptor.err).close();
+0

我仍然看到SimpleFormatter的輸出。我的logging.properties文件位於WEB-INF下。我如何檢查#2,#3和#4?謝謝你的幫助。 – DFB

+0

@DFB#2 System.getSecurityManager()。checkPermission。 #3&#4使用LogManager獲取所有記錄器名稱,然後按名稱詢問每個記錄器。 – jmehrens

+0

我應該檢查哪個權限?我無法在GAE中使用LogManager。它說GAE的Java運行時環境不支持LogManager。在我的代碼中,我只有信息和警告日誌(logger.info(「something」)和logger.warn(「something」))。它似乎沒有使用我的logging.properties。再次感謝您的幫助。 – DFB

相關問題