Search in sources :

Example 1 with HystrixRequestLog

use of com.netflix.hystrix.HystrixRequestLog in project Hystrix by Netflix.

the class HystrixRequestLogViaLoggerServletFilter method doFilter.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    StringBuilder requestURL = new StringBuilder();
    try {
        // get the requested URL for our logging so it can be associated to a particular request
        String uri = ((HttpServletRequest) request).getRequestURI();
        String queryString = ((HttpServletRequest) request).getQueryString();
        String method = ((HttpServletRequest) request).getMethod();
        requestURL.append(method).append(" ").append(uri);
        if (queryString != null) {
            requestURL.append("?").append(queryString);
        }
        chain.doFilter(request, response);
    } finally {
        try {
            if (HystrixRequestContext.isCurrentThreadInitialized()) {
                HystrixRequestLog log = HystrixRequestLog.getCurrentRequest();
                logger.info("Hystrix Executions [{}] => {}", requestURL.toString(), log.getExecutedCommandsAsString());
            }
        } catch (Exception e) {
            logger.warn("Unable to append HystrixRequestLog", e);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HystrixRequestLog(com.netflix.hystrix.HystrixRequestLog) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

HystrixRequestLog (com.netflix.hystrix.HystrixRequestLog)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1