Microservices logging with Spring and Keycloak

Radu Toev
Radu Toev
Aug 29, 2017 · 4 min read
[correlation-id] [user email] [date] [service name] [log level] [message]
Nothing fancy here :)

Correlation ID

Accessing the email

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(requestInterceptor);
}

Log statements

<Console name="Console-Appender" target="SYSTEM_OUT">
<PatternLayout>
<pattern>
%X{requestId} %X{userEmail} %d{yyyy-MM-dd HH:mm:ss} [ServiceName] [%-5level] %msg%n
</pattern>>
</PatternLayout>
</Console>
[3e232425-3432-4ace-bd60-3ea9ccab650a] [someone@email.com] 2017-08-29 12:20:04 [ServiceName] [INFO] Method Call

Caveat

[6566ca20..] [email] 2017-08-29 16:13:16 [ServiceName] [INFO] log1
2017-08-29 16:13:16 [ServiceName] [INFO] log2
[6566ca20..] [email] 2017-08-29 16:13:16 [ServiceName] [INFO] log1
[6566ca20..] [email] 2017-08-29 16:13:16 [ServiceName] [INFO] log2

Radu Toev

Written by

Radu Toev

Software Engineer https://softwarechain.io

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade