-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from RHoKAustralia/adding-aspects
Added Spring AOPs for application loggings
- Loading branch information
Showing
5 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/com/onemda/onemdabackend/aop/ExceptionLoggingAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.onemda.onemdabackend.aop; | ||
|
||
import org.aspectj.lang.annotation.AfterThrowing; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Aspect | ||
public class ExceptionLoggingAspect { | ||
|
||
Logger LOGGER = LoggerFactory.getLogger(ExceptionLoggingAspect.class); | ||
|
||
|
||
@AfterThrowing(pointcut="com.onemda.onemdabackend.aop.SystemArchitecture.Repository() ||" | ||
+ "com.onemda.onemdabackend.aop.SystemArchitecture.Service()", | ||
throwing="ex") | ||
public void logException(Exception ex) { | ||
LOGGER.error("Exception Occured: "+ex); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/com/onemda/onemdabackend/aop/PerformanceAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.onemda.onemdabackend.aop; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StopWatch; | ||
|
||
@Component | ||
@Aspect | ||
public class PerformanceAspect { | ||
|
||
Logger LOGGER = LoggerFactory.getLogger(PerformanceAspect.class); | ||
|
||
@Around("com.onemda.onemdabackend.aop.SystemArchitecture.Repository()") | ||
public void logPerformance(ProceedingJoinPoint joinPoint) throws Throwable { | ||
String methodInformation = joinPoint.getStaticPart().getSignature().toString(); | ||
|
||
StopWatch stopWatch = new StopWatch(methodInformation); | ||
stopWatch.start(); | ||
|
||
try { | ||
joinPoint.proceed(); | ||
} catch (Exception e) { | ||
// TODO: handle exception | ||
}finally { | ||
stopWatch.stop(); | ||
LOGGER.info(stopWatch.shortSummary()); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/com/onemda/onemdabackend/aop/SystemArchitecture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.onemda.onemdabackend.aop; | ||
|
||
import org.aspectj.lang.annotation.Pointcut; | ||
|
||
public class SystemArchitecture { | ||
|
||
//Any class annotated with @Repository | ||
@Pointcut("execution(* (@org.springframework.stereotype.Repository *).*(..))") | ||
public void Repository() { | ||
|
||
} | ||
|
||
@Pointcut("execution(* (@org.springframework.stereotype.Service *).*(..))") | ||
public void Service() { | ||
|
||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/onemda/onemdabackend/aop/TracingAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.onemda.onemdabackend.aop; | ||
|
||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.After; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Aspect | ||
public class TracingAspect { | ||
|
||
Logger LOGGER = LoggerFactory.getLogger(TracingAspect.class); | ||
|
||
@Before("com.onemda.onemdabackend.aop.SystemArchitecture.Repository() ||" | ||
+ "com.onemda.onemdabackend.aop.SystemArchitecture.Service()") | ||
public void logTheEntry(JoinPoint joinPoint ) { | ||
LOGGER.info("Entering into : "+joinPoint.getStaticPart().getSignature().toString()); | ||
} | ||
|
||
@After("com.onemda.onemdabackend.aop.SystemArchitecture.Repository() ||" | ||
+ "com.onemda.onemdabackend.aop.SystemArchitecture.Service()") | ||
public void logTheExit(JoinPoint joinPoint ) { | ||
LOGGER.info("Exiting from : "+joinPoint.getStaticPart().getSignature().toString()); | ||
} | ||
} |