如何使JAXRS 2(Jersey)详尽的Trace与ResourceConfig一起使用 [英] How to get JAXRS 2 (Jersey) verbose Trace to work with ResourceConfig

查看:129
本文介绍了如何使JAXRS 2(Jersey)详尽的Trace与ResourceConfig一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这样输出JAXRS的调试日志记录(按照文档 a>)...

I wish to output debugging logging for JAXRS like this (as per 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

但是我能做到的就是这个...

But all I can achieve is this...

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

后者是有用的,但它并没有向我显示事件链,即开始,预赛,比赛,REQ-FILTER,RI,INVOKE,RESP-FILTER,WI,完成.

The latter is useful, but it doesn't show me the chain of events, i.e. START, PRE-MATCH, MATCH, REQ-FILTER, RI, INVOKE, RESP-FILTER, WI, FINISHED.

在Amazon Web Services(AWS)下,我的AJAX请求似乎在大约12个小时后冻结(并不总是完全相同的时间),因此我希望看到的不仅仅是HTTP标头;我在链中走了多远/它在哪里卡住了?!

Under Amazon Web Services (AWS) my AJAX requests seem to freeze after around 12 hours (not always exactly the same time), so I'd like to see more than the HTTP header; how far am I getting in the chain / where is it getting stuck?!

这是我当前拥有的代码...

Here's the code I currently have...

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");

    }

}

似乎所有记录都由该行执行

It would seem that all of the logging is being performed by the line

register(new LoggingFilter());

并且以下几行似乎什么也没做

And that the following lines don't appear to do anything

property("jersey.config.server.tracing", "ALL");
property("jersey.config.server.tracing.threshold", "VERBOSE");

没有web.xml文件,它使用Servlet 3规范和JAXRS结合在一起来发现宁静的端点.

There's no web.xml file, it's using Servlet 3 spec and JAXRS combined to discover the restful endpoints.

在旧版本的JAXRS中,这似乎更简单.

In older versions of JAXRS this seemed simpler.

我应该指出,我在这种配置下使用Log4J,并且开始怀疑我是否需要对Java Logger/Bridge进行操作?

I should point out that I am using Log4J with this configuration and I'm starting to wonder whether I need to do something with the Java Logger / Bridge instead?

<?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>

我也尝试将根"级别更改为跟踪".

I have tried changing the Root level to 'trace' too.

推荐答案

所以您要使用的是LoggingFilter来查看响应标头,但看起来标头尚未添加LoggingFilter被调用的时间.标题 do 会显示在实际的响应标题中.您需要与客户确认才能看到他们.

So what you're trying to use is the LoggingFilter to see the response headers, but it doesn't look like the headers are added yet by the time the LoggingFilter is called. The headers do show up in the actual response headers though. You need to check with your client to see them.

就在服务器上登录而言,似乎需要将日志记录级别设置为FINER才能查看所有日志记录.我已经测试过了,情况似乎是这样.所有日志都以FINER的形式出现.要将跟踪日志记录级别仅设置为FINER,可以将其添加到日志记录属性文件中

As far as logging on the server, it appears the logging level needs to be set to FINER to see all the logging. I've tested and this seems to be the case. All the logs are coming out as FINER. To set only the tracing logging level to FINER, you can add this to you logging properties file

org.glassfish.jersey.tracing.level=FINER

请注意,这是Java Util日志记录.如果您不确定如何使用和配置此日志记录框架,那么这里有很多教程.

Note this is Java Util Logging. There are a bunch of tutorials out there, if you are not sure how to use and configure this logging framework.

这篇关于如何使JAXRS 2(Jersey)详尽的Trace与ResourceConfig一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆