1
|
/**
|
2
|
* Copyright (C) 2020 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.server.logging;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
|
13
|
import javax.servlet.ServletException;
|
14
|
import javax.servlet.http.HttpServletRequest;
|
15
|
import javax.servlet.http.HttpServletResponse;
|
16
|
|
17
|
import org.eclipse.jetty.server.Request;
|
18
|
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
19
|
import org.slf4j.MDC;
|
20
|
|
21
|
/**
|
22
|
* @author a.kohlbecker
|
23
|
* @since Jun 9, 2020
|
24
|
*/
|
25
|
public class InstanceLogWrapper extends HandlerWrapper {
|
26
|
|
27
|
/**
|
28
|
* Key under which the instance name stored in the
|
29
|
* Mapped Diagnostic Context (MDC)
|
30
|
*/
|
31
|
public static final String CDM_INSTANCE = "cdmInstance";
|
32
|
|
33
|
private String instanceName;
|
34
|
|
35
|
public InstanceLogWrapper(String instanceName) {
|
36
|
this.instanceName = instanceName;
|
37
|
}
|
38
|
|
39
|
@Override
|
40
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
41
|
throws IOException, ServletException {
|
42
|
|
43
|
// Collect Info for NDC/MDC
|
44
|
MDC.put(CDM_INSTANCE, instanceName);
|
45
|
try {
|
46
|
super.handle(target, baseRequest, request, response);
|
47
|
}
|
48
|
finally {
|
49
|
// Pop info out / clear the NDC/MDC
|
50
|
MDC.clear();
|
51
|
}
|
52
|
}
|
53
|
}
|