0

以下のコードが与えられた場合、スレッドが終了して最後の RequestTime を 1 つだけ取得するときに、どのようにすれば resquest 時間をログに記録できますか?

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    new ClientRequestContextHolder();
    logger.info("request filter ("+ ClientRequestContextHolder.getContext().getAttribute("uniqueId") +") started");
    filterChain.doFilter(request, response);
    logger.info("request filter ("+ ClientRequestContextHolder.getContext().getAttribute("uniqueId") +") finished");
    long st = (long)ClientRequestContextHolder.getContext().getAttribute("request_start");
    logger.info("RequestTime: " + customFormat("###,###.###",(System.nanoTime() - st)) + "ns");

}

私の現在の出力は次のようになります

INFO : com.app.context.ClientRequestContextHolder - initialized
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 7,958,694ns
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 12,657,404ns
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 13,942,554ns
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 14,579,297ns
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 16,428,276ns
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 17,329,786ns
INFO : com.app.filters.ClientRequestFilter - request filter (34) started
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 42,787,490ns
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 43,226,233ns
INFO : com.app.filters.ClientRequestFilter - request filter (34) finished
INFO : com.app.filters.ClientRequestFilter - RequestTime: 45,455,568ns
4

1 に答える 1