Skip to content

Commit

Permalink
Make code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli authored Apr 8, 2024
1 parent 757a62d commit 3858396
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,42 @@ public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {

@Around("applicationPackagePointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
LogLevel logLevel = determineLogLevel(joinPoint);
String methodName = joinPoint.getSignature().getName();
LogLevel logLevel = determineLogLevel(joinPoint);

logExecutionDetails(joinPoint, LogLevel.INFO, methodName + "() start execution");
logMethodParamsIfEnabled(joinPoint, logLevel, methodName);
logMethodStart(joinPoint, methodName);
logMethodParams(joinPoint, logLevel, methodName);

long start = System.currentTimeMillis();
Object result = joinPoint.proceed();
long end = System.currentTimeMillis();

logMethodResult(joinPoint, result, logLevel, methodName);
logMethodCompletion(joinPoint, methodName, end - start);

return result;
}

private void logMethodStart(ProceedingJoinPoint joinPoint, String methodName) {
logExecutionDetails(joinPoint, LogLevel.INFO, methodName + "() start execution");
}

private void logMethodParams(
ProceedingJoinPoint joinPoint, LogLevel logLevel, String methodName) {
logMethodParamsIfEnabled(joinPoint, logLevel, methodName);
}

private void logMethodResult(
ProceedingJoinPoint joinPoint, Object result, LogLevel logLevel, String methodName) {
logMethodResultIfEnabled(joinPoint, result, logLevel, methodName);
}

private void logMethodCompletion(
ProceedingJoinPoint joinPoint, String methodName, long timeTaken) {
logExecutionDetails(
joinPoint,
LogLevel.INFO,
methodName
+ "() finished execution and took ("
+ +(end - start)
+ ") mills to execute");

return result;
methodName + "() finished execution and took (" + timeTaken + ") mills to execute");
}

// Generic method to retrieve Loggable annotation
Expand Down Expand Up @@ -137,7 +152,13 @@ private void logMethodParamsIfEnabled(
Object[] args = joinPoint.getArgs();

for (int i = 0; i < args.length; i++) {
stringArrayList.add(parameterNames[i] + " : " + args[i]);
String paramName = parameterNames[i];
Object argValue = args[i];
// Check if the parameter name suggests it might contain sensitive data
if (paramName.matches("(?i).*(password|creditCard|ssn).*")) {
argValue = "REDACTED"; // Anonymize sensitive data
}
stringArrayList.add(paramName + " : " + argValue);
}
String argsString = String.join(", ", stringArrayList);
logExecutionDetails(joinPoint, logLevel, methodName + "() args :: -> " + argsString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,42 @@ public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {

@Around("applicationPackagePointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
LogLevel logLevel = determineLogLevel(joinPoint);
String methodName = joinPoint.getSignature().getName();
LogLevel logLevel = determineLogLevel(joinPoint);

logExecutionDetails(joinPoint, LogLevel.INFO, methodName + "() start execution");
logMethodParamsIfEnabled(joinPoint, logLevel, methodName);
logMethodStart(joinPoint, methodName);
logMethodParams(joinPoint, logLevel, methodName);

long start = System.currentTimeMillis();
Object result = joinPoint.proceed();
long end = System.currentTimeMillis();

logMethodResult(joinPoint, result, logLevel, methodName);
logMethodCompletion(joinPoint, methodName, end - start);

return result;
}

private void logMethodStart(ProceedingJoinPoint joinPoint, String methodName) {
logExecutionDetails(joinPoint, LogLevel.INFO, methodName + "() start execution");
}

private void logMethodParams(
ProceedingJoinPoint joinPoint, LogLevel logLevel, String methodName) {
logMethodParamsIfEnabled(joinPoint, logLevel, methodName);
}

private void logMethodResult(
ProceedingJoinPoint joinPoint, Object result, LogLevel logLevel, String methodName) {
logMethodResultIfEnabled(joinPoint, result, logLevel, methodName);
}

private void logMethodCompletion(
ProceedingJoinPoint joinPoint, String methodName, long timeTaken) {
logExecutionDetails(
joinPoint,
LogLevel.INFO,
methodName
+ "() finished execution and took ("
+ +(end - start)
+ ") mills to execute");

return result;
methodName + "() finished execution and took (" + timeTaken + ") mills to execute");
}

// Generic method to retrieve Loggable annotation
Expand Down Expand Up @@ -139,7 +154,13 @@ private void logMethodParamsIfEnabled(
Object[] args = joinPoint.getArgs();

for (int i = 0; i < args.length; i++) {
stringArrayList.add(parameterNames[i] + " : " + args[i]);
String paramName = parameterNames[i];
Object argValue = args[i];
// Check if the parameter name suggests it might contain sensitive data
if (paramName.matches("(?i).*(password|creditCard|ssn).*")) {
argValue = "REDACTED"; // Anonymize sensitive data
}
stringArrayList.add(paramName + " : " + argValue);
}
String argsString = String.join(", ", stringArrayList);
logExecutionDetails(joinPoint, logLevel, methodName + "() args :: -> " + argsString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,42 @@ public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {

@Around("applicationPackagePointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
LogLevel logLevel = determineLogLevel(joinPoint);
String methodName = joinPoint.getSignature().getName();
LogLevel logLevel = determineLogLevel(joinPoint);

logExecutionDetails(joinPoint, LogLevel.INFO, methodName + "() start execution");
logMethodParamsIfEnabled(joinPoint, logLevel, methodName);
logMethodStart(joinPoint, methodName);
logMethodParams(joinPoint, logLevel, methodName);

long start = System.currentTimeMillis();
Object result = joinPoint.proceed();
long end = System.currentTimeMillis();

logMethodResult(joinPoint, result, logLevel, methodName);
logMethodCompletion(joinPoint, methodName, end - start);

return result;
}

private void logMethodStart(ProceedingJoinPoint joinPoint, String methodName) {
logExecutionDetails(joinPoint, LogLevel.INFO, methodName + "() start execution");
}

private void logMethodParams(
ProceedingJoinPoint joinPoint, LogLevel logLevel, String methodName) {
logMethodParamsIfEnabled(joinPoint, logLevel, methodName);
}

private void logMethodResult(
ProceedingJoinPoint joinPoint, Object result, LogLevel logLevel, String methodName) {
logMethodResultIfEnabled(joinPoint, result, logLevel, methodName);
}

private void logMethodCompletion(
ProceedingJoinPoint joinPoint, String methodName, long timeTaken) {
logExecutionDetails(
joinPoint,
LogLevel.INFO,
methodName
+ "() finished execution and took ("
+ +(end - start)
+ ") mills to execute");

return result;
methodName + "() finished execution and took (" + timeTaken + ") mills to execute");
}

// Generic method to retrieve Loggable annotation
Expand Down Expand Up @@ -139,7 +154,13 @@ private void logMethodParamsIfEnabled(
Object[] args = joinPoint.getArgs();

for (int i = 0; i < args.length; i++) {
stringArrayList.add(parameterNames[i] + " : " + args[i]);
String paramName = parameterNames[i];
Object argValue = args[i];
// Check if the parameter name suggests it might contain sensitive data
if (paramName.matches("(?i).*(password|creditCard|ssn).*")) {
argValue = "REDACTED"; // Anonymize sensitive data
}
stringArrayList.add(paramName + " : " + argValue);
}
String argsString = String.join(", ", stringArrayList);
logExecutionDetails(joinPoint, logLevel, methodName + "() args :: -> " + argsString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,42 @@ public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {

@Around("applicationPackagePointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
LogLevel logLevel = determineLogLevel(joinPoint);
String methodName = joinPoint.getSignature().getName();
LogLevel logLevel = determineLogLevel(joinPoint);

logExecutionDetails(joinPoint, LogLevel.INFO, methodName + "() start execution");
logMethodParamsIfEnabled(joinPoint, logLevel, methodName);
logMethodStart(joinPoint, methodName);
logMethodParams(joinPoint, logLevel, methodName);

long start = System.currentTimeMillis();
Object result = joinPoint.proceed();
long end = System.currentTimeMillis();

logMethodResult(joinPoint, result, logLevel, methodName);
logMethodCompletion(joinPoint, methodName, end - start);

return result;
}

private void logMethodStart(ProceedingJoinPoint joinPoint, String methodName) {
logExecutionDetails(joinPoint, LogLevel.INFO, methodName + "() start execution");
}

private void logMethodParams(
ProceedingJoinPoint joinPoint, LogLevel logLevel, String methodName) {
logMethodParamsIfEnabled(joinPoint, logLevel, methodName);
}

private void logMethodResult(
ProceedingJoinPoint joinPoint, Object result, LogLevel logLevel, String methodName) {
logMethodResultIfEnabled(joinPoint, result, logLevel, methodName);
}

private void logMethodCompletion(
ProceedingJoinPoint joinPoint, String methodName, long timeTaken) {
logExecutionDetails(
joinPoint,
LogLevel.INFO,
methodName
+ "() finished execution and took ("
+ +(end - start)
+ ") mills to execute");

return result;
methodName + "() finished execution and took (" + timeTaken + ") mills to execute");
}

// Generic method to retrieve Loggable annotation
Expand Down Expand Up @@ -134,7 +149,13 @@ private void logMethodParamsIfEnabled(
Object[] args = joinPoint.getArgs();

for (int i = 0; i < args.length; i++) {
stringArrayList.add(parameterNames[i] + " : " + args[i]);
String paramName = parameterNames[i];
Object argValue = args[i];
// Check if the parameter name suggests it might contain sensitive data
if (paramName.matches("(?i).*(password|creditCard|ssn).*")) {
argValue = "REDACTED"; // Anonymize sensitive data
}
stringArrayList.add(paramName + " : " + argValue);
}
String argsString = String.join(", ", stringArrayList);
logExecutionDetails(joinPoint, logLevel, methodName + "() args :: -> " + argsString);
Expand Down

0 comments on commit 3858396

Please sign in to comment.