Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Lib
cloud
azure
OS Core Lib Azure
Commits
9795bf2d
Commit
9795bf2d
authored
Aug 13, 2020
by
Kishore Battula
Browse files
Added mdc context on start of request
parent
f0fa8b37
Pipeline
#5716
passed with stages
in 13 minutes and 36 seconds
Changes
3
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
9795bf2d
...
...
@@ -21,7 +21,7 @@
<groupId>
org.opengroup.osdu
</groupId>
<artifactId>
core-lib-azure
</artifactId>
<packaging>
jar
</packaging>
<version>
0.0.1
8
</version>
<version>
0.0.1
9
</version>
<name>
core-lib-azure
</name>
<properties>
...
...
src/main/java/org/opengroup/osdu/azure/filters/Slf4jMDCFilter.java
0 → 100644
View file @
9795bf2d
package
org.opengroup.osdu.azure.filters
;
import
org.opengroup.osdu.core.common.model.http.DpsHeaders
;
import
org.slf4j.MDC
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* MDC Filter for logging.
*/
@Component
@ConditionalOnProperty
(
value
=
"logging.mdccontext.enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
false
)
public
class
Slf4jMDCFilter
implements
Filter
{
@Autowired
private
DpsHeaders
dpsHeaders
;
/**
* Filter logic.
* @param servletRequest Request object.
* @param servletResponse Response object.
* @param filterChain Filter Chain object.
* @throws IOException
* @throws ServletException
*/
@Override
public
void
doFilter
(
final
ServletRequest
servletRequest
,
final
ServletResponse
servletResponse
,
final
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
MDC
.
setContextMap
(
getContextMap
());
filterChain
.
doFilter
(
servletRequest
,
servletResponse
);
MDC
.
clear
();
}
/**
* Method to create context map for mdc.
* @return Context map.
*/
private
Map
<
String
,
String
>
getContextMap
()
{
final
Map
<
String
,
String
>
contextMap
=
new
HashMap
<>();
contextMap
.
put
(
DpsHeaders
.
CORRELATION_ID
,
dpsHeaders
.
getCorrelationId
());
contextMap
.
put
(
DpsHeaders
.
DATA_PARTITION_ID
,
dpsHeaders
.
getPartitionId
());
return
contextMap
;
}
}
src/main/resources/log4j2.xml
View file @
9795bf2d
...
...
@@ -18,12 +18,12 @@
<Configuration
packages=
"com.microsoft.applicationinsights.log4j.v2"
>
<Properties>
<Property
name=
"LOG_PATTERN"
>
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.}
correlation-id=%X{correlation-id} data-partition-id=%X{data-partition-id}
: %m%n%ex
</Property>
</Properties>
<Appenders>
<Console
name=
"Console"
target=
"SYSTEM_OUT"
>
<PatternLayout
pattern=
"%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex"
/>
<PatternLayout
pattern=
"%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.}
correlation-id=%X{correlation-id} data-partition-id=%X{data-partition-id}
: %m%n%ex"
/>
</Console>
<ApplicationInsightsAppender
name=
"aiAppender"
>
</ApplicationInsightsAppender>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment