Skip to content

Commit 831901b

Browse files
Cavvekristinaxm
andauthored
Add filter for measuring request response time (#101)
* Added TimingFilter to measure request duration and log ms * Added TimingFilter to measure request duration and log ms --------- Co-authored-by: Kristina <kristina0x7@gmail.com>
1 parent 8b2b644 commit 831901b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.juv25d.filter;
2+
3+
import org.juv25d.http.HttpRequest;
4+
import org.juv25d.http.HttpResponse;
5+
import org.juv25d.logging.ServerLogging;
6+
7+
import java.io.IOException;
8+
import java.util.logging.Logger;
9+
10+
public class TimingFilter implements Filter {
11+
12+
private static final Logger logger = ServerLogging.getLogger();
13+
14+
@Override
15+
public void doFilter(HttpRequest req, HttpResponse res, FilterChain chain) throws IOException {
16+
long start = System.nanoTime();
17+
18+
chain.doFilter(req, res);
19+
20+
long durationMs = (System.nanoTime() - start) / 1_000_000;
21+
logger.info(req.method() + " " + req.path() + " took " + durationMs + " ms");
22+
23+
}
24+
}

0 commit comments

Comments
 (0)