修改app日志配置切入点

This commit is contained in:
xuwenbo
2020-09-03 09:59:56 +08:00
parent 05a3d114f3
commit 6b697e0021
18 changed files with 76 additions and 22 deletions

View File

@ -0,0 +1,22 @@
/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
*/
package co.yixiang.logging.aop.log;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author hupeng
* @date 2018-11-24
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AppLog {
String value() default "";
int type() default 0;
}

View File

@ -58,6 +58,15 @@ public interface LogService extends BaseService<Log> {
@Async
void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log,Long uid);
/**
* 保存app日志数据
* @param username 用户
* @param ip 请求IP
* @param joinPoint /
* @param log 日志实体
*/
@Async
void saveApp(String username, String ip, ProceedingJoinPoint joinPoint, Log log,Long uid);
/**
* 查询异常详情
* @param id 日志ID

View File

@ -11,6 +11,7 @@ import cn.hutool.json.JSONObject;
import co.yixiang.common.service.impl.BaseServiceImpl;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.logging.aop.log.AppLog;
import co.yixiang.logging.aop.log.Log;
import co.yixiang.logging.service.LogService;
import co.yixiang.logging.service.dto.LogErrorDTO;
@ -148,6 +149,55 @@ public class LogServiceImpl extends BaseServiceImpl<LogMapper, co.yixiang.loggin
this.save(log);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveApp(String username, String ip, ProceedingJoinPoint joinPoint,
co.yixiang.logging.domain.Log log, Long uid){
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
AppLog aopLog = method.getAnnotation(AppLog.class);
// 方法路径
String methodName = joinPoint.getTarget().getClass().getName()+"."+signature.getName()+"()";
StringBuilder params = new StringBuilder("{");
//参数值
Object[] argValues = joinPoint.getArgs();
//参数名称
String[] argNames = ((MethodSignature)joinPoint.getSignature()).getParameterNames();
if(argValues != null){
for (int i = 0; i < argValues.length; i++) {
params.append(" ").append(argNames[i]).append(": ").append(argValues[i]);
}
}
// 描述
if (log != null) {
log.setDescription(aopLog.value());
}
//类型 0-后台 1-前台
log.setType(aopLog.type());
if(uid != null) {
log.setUid(uid);
}
assert log != null;
log.setRequestIp(ip);
String loginPath = "login";
if(loginPath.equals(signature.getName())){
try {
assert argValues != null;
username = new JSONObject(argValues[0]).get("username").toString();
}catch (Exception e){
e.printStackTrace();
}
}
log.setAddress(StringUtils.getCityInfo(log.getRequestIp()));
log.setMethod(methodName);
log.setUsername(username);
log.setParams(params.toString() + " }");
this.save(log);
}
@Override
public Object findByErrDetail(Long id) {
co.yixiang.logging.domain.Log log = this.getById(id);