Add request tracing in logs using requestId in MDC and log config
All logging statements now automatically include a requestId which allows us to trace all logs produced in the application in response to one incoming request.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.1.1)
2023-07-15 00:37:37,531 [main] INFO c.e.c.g.m.MoodleGradingServiceApplication - Starting MoodleGradingServiceApplication v0.0.1-SNAPSHOT using Java 17.0.7 with PID 1 (/app/app.jar started by root in /app)
2023-07-15 00:37:37,533 [main] INFO c.e.c.g.m.MoodleGradingServiceApplication - No active profile set, falling back to 1 default profile: "default"
2023-07-15 00:37:41,833 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8082 (http)
2023-07-15 00:37:41,838 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8082"]
2023-07-15 00:37:41,840 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
2023-07-15 00:37:41,840 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/10.1.10]
2023-07-15 00:37:42,136 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2023-07-15 00:37:42,137 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 4410 ms
2023-07-15 00:37:44,129 [main] INFO o.s.b.a.e.web.EndpointLinksResolver - Exposing 1 endpoint(s) beneath base path '/actuator'
2023-07-15 00:37:44,255 [main] INFO o.s.s.web.DefaultSecurityFilterChain - Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@20921b9b, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@867ba60, org.springframework.security.web.context.SecurityContextHolderFilter@68ace111, org.springframework.security.web.header.HeaderWriterFilter@6f330eb9, org.springframework.security.web.authentication.logout.LogoutFilter@757f675c, ch.epfl.cs107.grading.moodle.api.v1.auth.filter.ApiKeyAuthenticationFilter@52b56a3e, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@6df20ade, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@4010d494, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@5ba745bc, org.springframework.security.web.access.ExceptionTranslationFilter@7ba63fe5, org.springframework.security.web.access.intercept.AuthorizationFilter@6759f091]
2023-07-15 00:37:44,938 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8082"]
2023-07-15 00:37:45,140 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8082 (http) with context path ''
2023-07-15 00:37:45,325 [main] INFO c.e.c.g.m.MoodleGradingServiceApplication - Started MoodleGradingServiceApplication in 9.582 seconds (process running for 11.061)
2023-07-15 00:37:54,442 [http-nio-8082-exec-1] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-07-15 00:37:54,522 [http-nio-8082-exec-1] INFO o.s.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
2023-07-15 00:37:54,525 [http-nio-8082-exec-1] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 3 ms
2023-07-15 00:37:54,735 4b786d2e-470f-4c6c-9b24-42faaf23b1e9 [http-nio-8082-exec-1] INFO c.e.c.g.m.a.v.c.PingController - Received a ping
2023-07-15 00:38:18,780 3329cc35-e47c-42c9-8ed9-75be305ee96b [http-nio-8082-exec-3] INFO c.e.c.g.m.a.v.c.PingController - Received a ping
This is the new log format
timestamp requestId thread level logger class log message
2023-07-15 00:37:54,735 4b786d2e-470f-4c6c-9b24-42faaf23b1e9 [http-nio-8082-exec-1] INFO c.e.c.g.m.a.v.c.PingController - Received a ping