Skip to content

Commit d6c7970

Browse files
committed
improve log for search
find queryString from request and added to log
1 parent a7e4198 commit d6c7970

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/main/java/ir/bigz/springbootreal/commons/generallog/AppLogAspect.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package ir.bigz.springbootreal.commons.generallog;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import ir.bigz.springbootreal.commons.util.Utils;
45
import ir.bigz.springbootreal.exception.AppException;
56
import ir.bigz.springbootreal.exception.HttpExceptionModel;
67
import org.aspectj.lang.JoinPoint;
8+
import org.aspectj.lang.Signature;
79
import org.aspectj.lang.annotation.*;
810
import org.slf4j.Logger;
911
import org.slf4j.LoggerFactory;
12+
import org.springframework.beans.factory.annotation.Autowired;
1013
import org.springframework.http.ResponseEntity;
1114
import org.springframework.stereotype.Component;
15+
import org.springframework.web.context.request.RequestContextHolder;
16+
import org.springframework.web.context.request.ServletRequestAttributes;
1217

18+
import javax.servlet.http.HttpServletRequest;
1319
import java.util.Arrays;
1420

1521
@Aspect
@@ -18,13 +24,23 @@ public class AppLogAspect {
1824

1925
private final Logger LOG = LoggerFactory.getLogger(AppLogAspect.class);
2026

27+
private final HttpServletRequest request;
28+
29+
public AppLogAspect(HttpServletRequest request) {
30+
this.request = request;
31+
}
32+
2133
@Before("ir.bigz.springbootreal.commons.generallog.CommonJoinPoint.controllerExecution()")
2234
public void beforeCallControllerMethod(JoinPoint joinPoint){
2335
String methodName = joinPoint.getSignature().getName();
2436
Object[] args = joinPoint.getArgs();
37+
String queryString = "";
38+
if(Utils.isNotNull(request.getQueryString())){
39+
queryString = request.getQueryString();
40+
}
2541
String reduce = Arrays.stream(args).reduce("", (s, s2) -> s + " " + s2).toString();
26-
LOG.info("before method: {} | argument: {}",
27-
methodName, reduce);
42+
LOG.info("before method: {} | argument: {} | queryString: {}",
43+
methodName, reduce, queryString);
2844
}
2945

3046
@AfterReturning(value = "ir.bigz.springbootreal.commons.generallog.CommonJoinPoint.controllerExecution()",

src/main/java/ir/bigz/springbootreal/dto/PageResult.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package ir.bigz.springbootreal.dto;
22

33
import lombok.Getter;
4+
import lombok.ToString;
45

56
import java.util.List;
67

78
@Getter
9+
@ToString
810
public class PageResult<T> {
911

1012
private final List<T> result;

0 commit comments

Comments
 (0)