【发布时间】:2015-08-08 21:24:48
【问题描述】:
感谢您对日志记录的建议。如我所说, 我尝试在 logging.properties 文件:
这是我的 appengine-.xml 文件,它指向 日志属性文件:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>uthreee</application>
<version>1</version>
<!--
Allows App Engine to send multiple requests to one instance in parallel:
-->
<threadsafe>true</threadsafe>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
<sessions-enabled>true</sessions-enabled>
</appengine-web-app>
这是日志属性文件
# 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>
#
java.util.logging.FileHandler.filter=F
# Set the default logging level for all loggers to WARNING
.level = FINEST
还有,这里是 F.java
import java.util.logging.Filter;
import java.util.logging.LogRecord;
public class F implements Filter {
public boolean isLoggable(LogRecord lr) {
String Str = lr.getSourceClassName();
Str = Str.toUpperCase();
int pos1;
pos = Str.indexOf("STATUS");
pos1 =
System.out.println ("pos "+pos);
if (pos>=0) {
return false;
}
else {
return true;
}
}}
这是我想要抑制的日志信息:
2015-05-28 18:00:12.207 /api/get/status?_=1432861201589 200 19ms 0kb Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0 module=default version=1
I 2015-05-28 18:00:12.196 StatusServlet doGet: entering status servlet 1
I 2015-05-28 18:00:12.196 GenerationUtil TimerOK: Timer OK d:Fri May 29 01:00:12 UTC 2015 e: Fri May 15 14:47:30 UTC 2015Logical:true
D 2015-05-28 18:00:12.200 GenerationUtil currentSizeOfGeneration: FINE: Generation 1 currently has 10 chromosomes.
I 2015-05-28 18:00:12.200 GenerationUtil checkForQuorum: check quorum returning true
I 2015-05-28 18:00:12.200 StatusServlet doGet: TIMER OK true Q true
I 2015-05-28 18:00:12.200 StatusServlet doGet: HERE C
I 2015-05-28 18:00:12.200 GenerationUtil getCount: DEBUG: get Count status (ga) = 1 Key|generation(1)|
D 2015-05-28 18:00:12.206 GenerationUtil getCount: DEBUG: gcf; count 2
D 2015-05-28 18:00:12.206 GenerationUtil getCount: returning for gen1 value is 2
I 2015-05-28 18:00:12.206 GenerationUtil checkForSufficientRatings: DEBUG: check for Sufficient Ratings 1 count 2quorum 4
I 2015-05-28 18:00:12.206 GenerationUtil checkForSufficientRatings: DEBUG: insufficient ratings , returning false
I 2015-05-28 18:00:12.206 StatusServlet doGet: DEBUG:1 false
【问题讨论】:
-
查看文档:cloud.google.com/appengine/docs/java/logs AppEngine 使用 java.util.logging 但您可以编写外观并使用自己的类。我个人使用我也推荐的 slf4j。即使您禁用了 servlet 的日志记录,该 url 仍会显示在日志中,因为日志也会显示请求本身。还要检查您的
logging.properties文件以了解您的最低日志记录级别。如果您使用自己的外观,您可以使用FINEST作为您的设置。 -
感谢您与我分享指向“日志 Java API 概述”的链接cloud.google.com/appengine/docs/java/logs 这告诉 API 检索已记录在 Google appengine 系统上的日志。它并没有告诉人们如何控制最初记录的内容。感谢您提到可以编写外观或使用 slf4j。但是,我没有看到有关如何告诉 Google Appengine 使用其中任何一个的文档。我是否应该创建自己的过滤器类并简单地在 logging.properties、属性 java.util.logger.FileHandler.filter 中使用?
-
这些是很多不同的问题。要使用 slf4j,你需要将 slf4j-api 和 slf4j-jdk14 的 jars 放在你的类路径中。同样:App Engine 使用
java.util.logging。您可能想查看java.util.logging的文档。此处描述了应用引擎和 java.util.logging 之间的桥梁:cloud.google.com/appengine/articles/logging
标签: java google-app-engine servlets logging