A Java library to ease the life of web developers by providing automatic logging of input, output, and some context data for controllers
> INFO:
getUser()
called via url
[http://localhost:8080/get-random-user],
username [username]
> INFO:
getUser()
took
[1.8 ms]
to complete
> INFO:
getUser()
returned:
[User(id=SP-937-215,
email=jeanlucpicard@starfleet.com,
password=xxxxx,
firstName=Jean-Luc,
lastName=Picard)]
> INFO:
getMemo()
called via url
[http://localhost:8080/get-memo],
username [username]
> INFO:
getMemo()
took
[0.2 ms]
to complete
> INFO:
getMemo()
returned:
[Memo(id=m_xyz_123, text=Hello, World! From a Memo!)]
> INFO:
getUser()
called via url
[http://localhost:8080/get-random-user],
username [username]
> INFO:
getUser()
took
[1.8 ms]
to complete
> INFO:
getUser()
returned:
[User(id=SP-937-215,
email=jeanlucpicard@starfleet.com,
password=xxxxx,
firstName=Jean-Luc,
lastName=Picard)]
> INFO:
getMemo()
called via url
[http://localhost:8080/get-memo],
username [username]
> INFO:
getMemo()
took
[0.2 ms]
to complete
> INFO:
getMemo()
returned:
[Memo(id=m_xyz_123, text=Hello, World! From a Memo!)]
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!
Precisely control what gets logged and what doesn't. Use provided annotations to achieve fine-grain control over logging. More customizations to follow soon.
Prevent sensitive data such as passwords, API keys from being logged via data scrubbing. Easily extend items to be scrubbed for customized security.
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 moreWe 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.
> INFO:
getResource() called with arguments apiKey: [xxxxx]
called via url
[http://localhost:8080/get-resource],
username [username]
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 } }
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 }
compile 'io.github.harshilsharma63:controller-logger:1.2.3'
@Bean public GenericControllerAspect genericControllerAspect() { return new GenericControllerAspect(); }
@Logging @RestController public class UserController { ... }
Check out the example project demonstrating the capabilities of this library
The primary computers on my Starship use Harshil's Controller Logger and I love it! I'm currently negotiating a peace treaty with Klingons and sharing knowledge of this library is my top priority in the technology exchange program.
Starfleet, United Federation of Planets
I'm a Vulcan, I speak only that which is logical and true. This library, the Controller Logger, is a work of logic and a pure mind. I wish its creators and users may live long and prosper.
Starfleet, United Federation of Planets
Being a chief of security on an open space station is not an easy task, to say the least. But this lovely piece of software, the Controller Logger, makes it much easier. With logs for each activity, I can monitor the whole place from my office itself!
Bajoran Militia