Skip to content

utkuertunc/Spring-Async-AOP-Logger-CustomAnnotation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Working Asynchronous and logging with Custom AOP Annotation

This project has three main goals => Logging with AOP, processing asynchronous and thread safe.

Outputs are located at the bottom of the page.

Why did I use Aspect? (Cross Cutting)

Cause I want to get log parameter when before the method return and i want get log return type when after returning. (with timestamp)

I use AspectJ for that. (@Before and @AfterReturning)

Why did I use Custom Annotation?

Cause If I want to ignore parameter or return type for log, I can add a value of annotation and DONE!

So I added ignoreparam and ignorereturn values for the annotation. Aspect is wired to the annotation.

Asynchronous Programming

Maybe asynchronous logging is not good idea for this project but this is only demo.

I used GitHub API for getting users. Threads are working in asynchronous. Also Aspect Logger doing the job in asynchronous.

GitHub User Service

Logger and RestTemplate defined final for thread safe. Threads are getting in Thread Pool (threadPoolTaskExecutor).

image

Custom Annotation

This annotations target is method level and works runtime.

ignorereturn is default false and ignoreparam is default empty string.

image

Aspect

Defined pointcut for annotation. Getting parameter name and annotation with reflection and joinpoint.

Then checking string in the service methods parameter and getting logs. Same thing for the return type.

image

image

Outputs

This one has parameter name and return type. You can see the asynchronous threads. They are working diffrent order.

async

1- Logging parameters before the method returns => Processes queue is 3,1,2,4

2- Getting user with GitHub API => Processes queue is 3,2,4,1

3- Logging return type after the metod returns => Processes queue is 4,2,3,1

This one has ignoreparam and ignorereturn values. Same processes are asynchronous again but log is not getting return type and parameter.

image

image

About

Logger with Custom Aspect Annotation (Async)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages