Member-only story

Easy mass-logging with AspectJ maven plugin

Logging anything without changes in the application code

Marian C.
6 min readJan 7, 2022

I love to have detailed logs, but I hate seeing repetitive code like calls to a logger.

Normally Java applications have logs. For debugging or performance monitoring it can be very convenient to store in the log not only conditional diagnostic messages but also execution times of the key methods. Logging execution times is so effortless to implement, that one needs to have a valid reason why not to implement it just in case.

In this post I demonstrate the ease of mass-logging using a tiny sample web application. The full details of this ancient but very useful technique you can find in the documentation of AspectJ maven plugin and the documentation of AspectJ library.

Tracing methods in annotated classes

Backends of a web application typically include several REST resources relaying data between browsers and a database. For performance monitoring, I need to keep log with execution times of each resource method. How to do that? There three obvious options:

  • Using copy and paste to pollute each resource method with identical lines calling a logger.
  • To add a filter interception HTTP requests from the REST…

--

--

Marian C.
Marian C.

Written by Marian C.

Java, JavaScript and SQL developer. Interested in data collection and visualization.

Responses (2)