Automatic API Logging For Spring

A Java library to ease the life of web developers by providing automatic logging of input, output, and some context data for controllers

> 2018-02-26 16:52:35.419 INFO: getUser() called via url [http://localhost:8080/get-random-user], username [username]

> 2018-02-26 16:52:35.624 INFO: getUser() took [1.8 ms] to complete

> 2018-02-26 16:52:35.624 INFO: getUser() returned: [User(id=SP-937-215, email=jeanlucpicard@starfleet.com, password=xxxxx, firstName=Jean-Luc, lastName=Picard)]

> 2018-02-26 16:52:35.419 INFO: getMemo() called via url [http://localhost:8080/get-memo], username [username]

> 2018-02-26 16:52:35.624 INFO: getMemo() took [0.2 ms] to complete

> 2018-02-26 16:52:35.624 INFO: getMemo() returned: [Memo(id=m_xyz_123, text=Hello, World! From a Memo!)]

> 2018-02-26 16:52:35.419 INFO: getUser() called via url [http://localhost:8080/get-random-user], username [username]

> 2018-02-26 16:52:35.624 INFO: getUser() took [1.8 ms] to complete

> 2018-02-26 16:52:35.624 INFO: getUser() returned: [User(id=SP-937-215, email=jeanlucpicard@starfleet.com, password=xxxxx, firstName=Jean-Luc, lastName=Picard)]

> 2018-02-26 16:52:35.419 INFO: getMemo() called via url [http://localhost:8080/get-memo], username [username]

> 2018-02-26 16:52:35.624 INFO: getMemo() took [0.2 ms] to complete

> 2018-02-26 16:52:35.624 INFO: getMemo() returned: [Memo(id=m_xyz_123, text=Hello, World! From a Memo!)]

Using this library?
HIGHLIGHTS

Features you love

Simple

Create a bean, add an annotation to your class and you're ready to rock! It takes just six lines total to add it to a project!

Customize

Precisely control what gets logged and what doesn't. Use provided annotations to achieve fine-grain control over logging. More customizations to follow soon.

Secure

Prevent sensitive data such as passwords, API keys from being logged via data scrubbing. Easily extend items to be scrubbed for customized security.

Discover Productivity!

While working on a project, a Spring-based web application, it quickly became annoying adding the same log statements for each new controller method being created. Working in a team made it inconsistent too with people forgetting or adding unformatted logs. This was the perfect use case for AOP (Aspect Oriented Programming). This library is re-built based on experience gained during my original implementation of AOP based logging.

No more incomplete logs. No more inconsistent logs. Always be ready with complete information for debugging or tracing down errors.

Read more
FEATURES

Do more with our app

Prevent logging sensitive information

We make no compromises with your security

With a data scrubbing feature (enabled by default) built in, you don't need to worry about sensitive information getting logged. It scrubs information such as passwords, auth tokens, API keys and you can extend it as well to match your custom requirements.

> 2018-02-26 16:52:35.419 INFO: getResource() called with arguments apiKey: [xxxxx] called via url [http://localhost:8080/get-resource], username [username]

Fine-Grain Control

Use provided annotations to fine-grain your logging setup

Using the @Logging and @NoLogging annotations, target exactly the classes and methods you want logging to work for or to skip.

@RestController
@Logging
public class UserController {
    // everything here will be logged
    // due to @Logging annotation on class
    ...

    @NoLogging
    @RequestMapping("/is-active")
    @RequestBody
    public bool isActive(@RequestParam String userId) {
        // expect this
        // this won't be logged due to @NoLogging on this method
    }
}
                                

Has no effect on your code

Your business logic stays unaffected

Your business logic stays unaffected by any error that may occur (just saying!) in the logging logic. Your code gets executed every time, as if you never had this library!

// the code is on similar lines...
try {
    // all the logging logic...
} catch (Exception e) {
    // catches anything that goes wrong. Doesn't really happen though :D
}

result = proceedingJoinPoint.proceed(); // your business logic is execited here

try {
    // post execution logging logic ...
} catch (Exception e) {
    // catch everything
}
                            

Launch your App

What are you thinking? Give it a try!

Check out the example project over here or quickly add to your own project.

Read more
  • 1 Add project dependency

    compile 'io.github.harshilsharma63:controller-logger:1.2.3'

  • 2 Create a bean for AOP weaver to pick

    @Bean
    public GenericControllerAspect genericControllerAspect() {
        return new GenericControllerAspect();
    }

  • 3 Annotate your controller class

    @Logging
    @RestController
    public class UserController {
        ...
    }
    

Check out the example project demonstrating the capabilities of this library

TESTIMONIALS

What our Customers Says