forked from robaho/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggingFilter.java
More file actions
39 lines (31 loc) · 997 Bytes
/
LoggingFilter.java
File metadata and controls
39 lines (31 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package robaho.net.httpserver;
import java.util.*;
import java.util.logging.Logger;
import java.text.*;
import java.io.*;
import com.sun.net.httpserver.*;
public class LoggingFilter extends Filter {
private final Logger logger;
private final DateFormat df;
public LoggingFilter(Logger logger) throws IOException {
df = DateFormat.getDateTimeInstance();
this.logger = logger;
}
/**
* The filter's implementation, which is invoked by the server
*/
public void doFilter(HttpExchange t, Filter.Chain chain) throws IOException {
chain.doFilter(t);
String s = df.format(new Date());
s = s + " " + t.getRequestMethod() + " " + t.getRequestURI() + " ";
s = s + " " + t.getResponseCode() + " " + t.getRemoteAddress();
logger.info(s);
}
public void init(HttpContext ctx) {
}
public String description() {
return "Request logger";
}
public void destroy(HttpContext c) {
}
}