title: How to add request filters in Play framework?
body: <p>I would like to show in my logs, the time that could takes every request or action..</p>
  
  <p>I added this class to my controller but nothing happen in my log!!!!
  what should i do to show request time in my log please ?</p>
  
  <p>thank you in advance.
  <a href="https://www.playframework.com/documentation/2.5.x/JavaHttpFilters" rel="nofollow noreferrer">Reference of Class</a></p>
  
  <pre><code>import java.util.concurrent.CompletionStage;
  import java.util.function.Function;
  import javax.inject.Inject;
  import akka.stream.Materializer;
  import play.Logger;
  import play.mvc.*;
  
  public class LoggingFilter extends Filter {
  
      @Inject
      public LoggingFilter(Materializer mat) {
          super(mat);
      }
  
      @Override
      public CompletionStage&lt;Result&gt; apply(
              Function&lt;Http.RequestHeader, CompletionStage&lt;Result&gt;&gt; nextFilter,
              Http.RequestHeader requestHeader) {
          long startTime = System.currentTimeMillis();
          return nextFilter.apply(requestHeader).thenApply(result -&gt; {
              long endTime = System.currentTimeMillis();
              long requestTime = endTime - startTime;
  
              Logger.info("{} {} took {}ms and returned {}",
                  requestHeader.method(), requestHeader.uri(), requestTime, result.status());
  
              return result.withHeader("Request-Time", "" + requestTime);
          });
      }
  }
  </code></pre>