How to Build an Effective Logging System Using Aspect and Spring Cloud Sleuth

Ruby Valappil
Javarevisited
Published in
4 min readJun 17, 2022

--

Photo by Nubelson Fernandes on Unsplash

Good logging practice is one of the most critical aspects of software development. It helps to quickly extract the context and isolate the problem while debugging production issues.

The biggest challenge though comes when the team doesn't have a logging system in place. If everyone follows a logging style that he/she feels is right then the person debugging a production issue will find it extremely challenging and annoying to follow a new pattern to analyze logs every time.

On the other hand, when we build a software system if we could add a basic logging framework that would capture the most essential pieces needed to debug the code then we leave little scope for manual errors.

In this article, we are trying to achieve the below given three tasks.

  1. Tracking each API call using a unique Id — This would help us track all the steps involved in a single code flow.
  2. Tracking any Asynchronous calls under the caller's unique Id — Tracking async calls becomes difficult unless we pass a unique Id as a method parameter and log it explicitly. This has scope for manual error.
  3. Logging the API Requests — This is needed to identify the API path that we need to investigate and verify each API call using…

--

--