[Java] A method logger lib with Spring AOP

1 minute read

MethodLogger is a java lib based in Spring AOP for logging method calls, exposing execution time, serialized returned object and more. This is how you can use it:

1. Setup

This lib is available through Jitpack, so if you want to use it just add the Jitpack repo and reference the dependency as follows:


2. Enabling the lib to be scanned by Spring

To enable MethodLogger, add @EnableMethodLogger to your Spring application

public class MyApplication {
	public static void main(String[] args) {
		SpringApplication.run(MyApplication.class, args);

3. Annotate the method

With MethodLogger, just annotate the method you want to be logged with @LogMethod

class AwesomeClass {

    DummyRepository dummyRepo;

    public DummyClass getDummy(final Long id) {
        return dummyRepo.get(id);

class DummyClass {
    private String foo;
    private Long bar;
    // getters, setters...

4. When the method is called, this it the default log output:

AwesomeClass -> getDummy(123): [15 ms]

With the show-result option enabled, you will get it like this:

AwesomeClass -> getDummy(123): {
    "foo": "asdf",
    "bar": 123456
} [15 ms]

For more details, source at Github