Skip to content

Commit df23745

Browse files
Add Filter to Get VCAP metadate from Environment
1 parent d8af3fe commit df23745

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.sap.hcp.cf.logging.servlet.filter;
2+
3+
import javax.servlet.http.HttpServletRequest;
4+
import javax.servlet.http.HttpServletResponse;
5+
6+
import com.sap.hcp.cf.logging.common.LogContext;
7+
8+
/**
9+
* <p>
10+
* The {@link AddVcapEnvironmentToLogContextFilter} extracts CF specific
11+
* metadata about the running application and adds it to the log context. The
12+
* metadata includes the app, org and space names and ids. This allows to
13+
* attribute a generated log message to the correct source from the message
14+
* alone.
15+
* </p>
16+
*
17+
* <p>
18+
* <b>Note:</b> This metadata can usually also be obtained from the CF channel
19+
* shipping the logs, e.g. syslog structured data. Hence, depending on the
20+
* use-case, it may not be required to add the metadata with this filter.
21+
* </p>
22+
*/
23+
public class AddVcapEnvironmentToLogContextFilter extends AbstractLoggingFilter {
24+
25+
@Override
26+
protected void preProcess(HttpServletRequest request, HttpServletResponse response) {
27+
LogContext.loadContextFields();
28+
}
29+
30+
@Override
31+
protected void postProcess(HttpServletRequest request, HttpServletResponse response) {
32+
LogContext.resetContextFields();
33+
}
34+
}

0 commit comments

Comments
 (0)