rev:操作日志问题修改

This commit is contained in:
2023-09-08 10:39:57 +08:00
parent 540f0f0504
commit af088d123e
3 changed files with 14 additions and 29 deletions

View File

@@ -15,7 +15,7 @@ import javax.sql.DataSource;
@Configuration @Configuration
@Slf4j @Slf4j
public class DataBaseConfig implements TransactionManagementConfigurer { public class DataBaseConfig {
@Primary @Primary
@Bean(name = "dataSource") @Bean(name = "dataSource")
@@ -24,20 +24,4 @@ public class DataBaseConfig implements TransactionManagementConfigurer {
return new DruidDataSource(); return new DruidDataSource();
} }
@Resource(name="transactionManager")
private PlatformTransactionManager transactionManager;
// 创建事务管理器
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
// 实现接口 TransactionManagementConfigurer 方法,其返回值代表在拥有多个事务管理器的情况下默认使用的事务管理器
@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
return transactionManager;
}
} }

View File

@@ -148,9 +148,9 @@ public class StringUtils {
*/ */
public static String getIp(HttpServletRequest request) { public static String getIp(HttpServletRequest request) {
// TODO 不解析IP地址 // TODO 不解析IP地址
if(true){ // if(true){
return "127.0.0.1"; // return "127.0.0.1";
} // }
String ip = request.getHeader("x-forwarded-for"); String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {

View File

@@ -27,6 +27,7 @@ import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import org.nl.common.utils.IdUtil; import org.nl.common.utils.IdUtil;
import org.nl.modules.common.utils.RequestHolder; import org.nl.modules.common.utils.RequestHolder;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.common.utils.StringUtils; import org.nl.modules.common.utils.StringUtils;
import org.nl.modules.common.utils.ThrowableUtil; import org.nl.modules.common.utils.ThrowableUtil;
import org.nl.modules.logging.domain.Log; import org.nl.modules.logging.domain.Log;
@@ -93,7 +94,7 @@ public class LogAspect {
//是否把日志存到日志表 //是否把日志存到日志表
if (logInfo.isAddLogTable()) { if (logInfo.isAddLogTable()) {
Log log = new Log("INFO", System.currentTimeMillis() - startTime); Log log = new Log("INFO", System.currentTimeMillis() - startTime);
logService.save("", StringUtils.getBrowser(request), requestIp, joinPoint, log); logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log);
} }
if (logInfo.isInterfaceLog()) { if (logInfo.isInterfaceLog()) {
try { try {
@@ -122,7 +123,7 @@ public class LogAspect {
log.error("track_id:{},error:{}", trackId, ex.getMessage()); log.error("track_id:{},error:{}", trackId, ex.getMessage());
Log log = new Log("ERROR", System.currentTimeMillis() - startTime); Log log = new Log("ERROR", System.currentTimeMillis() - startTime);
log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes()); log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes());
logService.save("", StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log); logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
throw ex; throw ex;
} }
return result; return result;
@@ -158,11 +159,11 @@ public class LogAspect {
return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList); return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList);
} }
// public String getUsername() { public String getUsername() {
// try { try {
// return SecurityUtils.getCurrentUsername(); return SecurityUtils.getCurrentUsername();
// } catch (Exception e) { } catch (Exception e) {
// return ""; return "";
// } }
// } }
} }