Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/avidee007/custom-logger-advice

Custom annotation to separate logging concerns from business layer. Works with spring AOP to perform advice to custom annotation to do console and database logging.
https://github.com/avidee007/custom-logger-advice

annotations generics-in-java rest-api spring-aop spring-boot spring-data-jpa

Last synced: 28 days ago
JSON representation

Custom annotation to separate logging concerns from business layer. Works with spring AOP to perform advice to custom annotation to do console and database logging.

Awesome Lists containing this project

README

        

# Custom Logger Advice Service

**Problem**

Sometimes we need to push request details in a database for tracking purposes,
and this can be an overhead to API performance.
This requires additional handling of database persistence logic which can slow and
cause issues to overall API performance.

**Solution**

* Custom annotation `@LoggerAdvice` to separate logging concern from service/business layer code.

* This annotation has **logToDb** flag which can decide whether logs push logs to database table.

* This annotation uses spring AOP, to do logging as advice to `@LoggerAdvice` annotation.

* When logToDb is set to true it persists the request entity asynchronously to do persistence in
separate thread to avoid any API performance issues.

**How to use @LoggerAdvice:**

This is method level annotation can be applied to any method to use it.

`@LoggerAdvice
public void methodWithOutDbLogging() {
// actual method code logic
}`

`@LoggerAdvice(logToDb = true)
public void methodWithDbLogging() {
// actual method code logic
}`

**Custom Logger Advice Service was built with below components**

* spring-web: To build RESTFul api.
* spring-aop: To build logger advice for @LoggerAdvice annotation
* spring-data-jpa: To do persistence of entities in database.
* postreSQL: Database
* Junit and Mockito: For unit testing