我希望像这样输出JAXRS的调试日志(根据documentation)...
3 X-Jersey-Tracing-000: START [ ---- / ---- ms | ---- %] baseUri=[http://localhost:9998/ALL/] requestUri=[http://localhost:9998/ALL/root/sub-resource-locator/sub-resource-method] method=[POST] authScheme=[n/a] accept=[application/x-jersey-test] accept-encoding=n/a accept-charset=n/a accept-language=n/a content-type=[application/x-jersey-test] content-length=[11]
4 X-Jersey-Tracing-001: PRE-MATCH [ 0.01 / 0.68 ms | 0.01 %] PreMatchRequest summary: 2 filters
5 X-Jersey-Tracing-002: MATCH [ 8.44 / 9.15 ms | 4.59 %] RequestMatching summary
6 X-Jersey-Tracing-003: REQ-FILTER [ 0.01 / 9.20 ms | 0.00 %] Request summary: 2 filters
7 X-Jersey-Tracing-004: RI [86.14 / 95.49 ms | 46.87 %] ReadFrom summary: 3 interceptors
8 X-Jersey-Tracing-005: INVOKE [ 0.04 / 95.70 ms | 0.02 %] Resource [org.glassfish.jersey.tests.integration.tracing.SubResource @901a4f3] method=[public org.glassfish.jersey.tests.integration.tracing.Message org.glassfish.jersey.tests.integration.tracing.SubResource.postSub(org.glassfish.jersey.tests.integration.tracing.Message)]
9 X-Jersey-Tracing-006: RESP-FILTER [ 0.01 / 96.55 ms | 0.00 %] Response summary: 2 filters
10 X-Jersey-Tracing-007: WI [85.95 / 183.69 ms | 46.77 %] WriteTo summary: 4 interceptors
11 X-Jersey-Tracing-008: FINISHED [ ---- / 183.79 ms | ---- %] Response status: 200/SUCCESSFUL|OK
但我能做到的就是这个......
03-Feb-2016 13:18:17.027 INFO [http-nio-8084-exec-270] org.glassfish.jersey.filter.LoggingFilter.log 3 * Server has received a request on thread http-nio-8084-exec-270
3 > GET http://localhost:8084/SocialScheduler/rest/dostuff?startDate=03%2F02%2F2016%2013%3A17&endDate=04%2F02%2F2016%2013%3A17&resolutionMins=720&_=1454505462184
3 > accept: application/json, text/javascript, */*; q=0.01
3 > accept-encoding: gzip, deflate, sdch
3 > accept-language: en-US,en;q=0.8
3 > connection: keep-alive
3 > cookie: JSESSIONID=7BDAEC5068C7A8F6FE26263EBF6998CE; cookieconsent_dismissed=yes; cookie_assistant_enable_cookies=true; __uvt=; _ga=GA1.1.1324172961.1446064949; _gat=1; __smToken=6obzPmlxzCuYugw7AHhVSuH7; linkedin_oauth_773fp8xagqy7nf_crc=null; uvts=3jj9UU7vonmXljiC
3 > host: localhost:8084
3 > referer: http://localhost:8084/projectx/app.jsp
3 > user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36
3 > x-requested-with: XMLHttpRequest
03-Feb-2016 13:18:17.080 INFO [http-nio-8084-exec-270] org.glassfish.jersey.filter.LoggingFilter.log 3 * Server responded with a response on thread http-nio-8084-exec-270
3 < 200
3 < Content-Type: application/json
后者很有用,但它并没有向我展示事件链,即START,PRE-MATCH,MATCH,REQ-FILTER,RI,INVOKE,RESP-FILTER,WI,FINISHED。
在Amazon Web Services(AWS)下,我的AJAX请求似乎在大约12小时后(并非总是完全相同的时间)冻结,因此我希望看到的不仅仅是HTTP标头;我在链条中走了多远/哪里卡住了?!
这是我目前的代码......
package uk.co.devology.projectx;
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.server.ResourceConfig;
@ApplicationPath("/rest/*")
public class RestResourceConfig extends ResourceConfig {
public RestResourceConfig() {
packages("uk.co.devology.projectx");
register(new LoggingFilter());
// property(ServerProperties.TRACING, "ALL");
// property(ServerProperties.TRACING_THRESHOLD, "SUMMARY");
property("jersey.config.server.tracing", "ALL");
property("jersey.config.server.tracing.threshold", "VERBOSE");
}
}
似乎所有日志记录都是由行执行
register(new LoggingFilter());
并且以下几行似乎没有做任何事情
property("jersey.config.server.tracing", "ALL");
property("jersey.config.server.tracing.threshold", "VERBOSE");
没有web.xml文件,它使用Servlet 3规范和JAXRS组合来发现宁静的端点。
在旧版本的JAXRS中,这似乎更简单。
我应该指出我正在使用Log4J进行此配置,而我开始怀疑是否需要对Java Logger / Bridge执行某些操作?
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%p %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
我尝试将根级别更改为&#39; trace&#39;太
答案 0 :(得分:2)
因此,您尝试使用的是LoggingFilter
来查看响应标头,但是在LoggingFilter
被调用时,它看起来似乎尚未添加标头。然而,标题 do 显示在实际的响应头中。您需要与您的客户联系以查看它们。
就登录服务器而言,似乎需要将日志记录级别设置为FINER
以查看所有日志记录。我已经测试过,这似乎就是这种情况。所有日志都以FINER
形式出现。要仅将跟踪日志记录级别设置为FINER
,可以将其添加到日志记录属性文件
org.glassfish.jersey.tracing.level=FINER
请注意,这是Java Util Logging。如果您不确定如何使用和配置此日志记录框架,那么有很多教程。