mirror of https://gitee.com/stylefeng/roses
【log】整理log模块引用,根据配置文件初始化不同的日记记录器
parent
983c909aad
commit
ac94d92218
|
@ -0,0 +1,22 @@
|
|||
package cn.stylefeng.roses.kernel.log.api.pojo.log;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 日志配置信息
|
||||
*
|
||||
* @author liuhanqing
|
||||
* @date 2020-12-20 13:53
|
||||
**/
|
||||
@Data
|
||||
public class SysLogProperties {
|
||||
/**
|
||||
* 日志存储类型:db-数据库,file-文件,默认存储在数据库中
|
||||
*/
|
||||
private String type = "db";
|
||||
|
||||
/**
|
||||
* file存储类型日志文件的存储位置
|
||||
*/
|
||||
private String fileSavePath = "_sys_log";
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.aspectj.lang.annotation.Pointcut;
|
|||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
@ -30,6 +31,7 @@ import java.util.Map;
|
|||
* @date 2020/10/28 17:06
|
||||
*/
|
||||
@Aspect
|
||||
//@Component
|
||||
@Slf4j
|
||||
public class RequestApiLogRecordAop implements Ordered {
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import cn.stylefeng.roses.kernel.log.db.entity.SysLog;
|
|||
import cn.stylefeng.roses.kernel.log.db.service.SysLogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -27,7 +28,7 @@ import java.util.stream.Collectors;
|
|||
* @author luojie
|
||||
* @date 2020/11/2 15:50
|
||||
*/
|
||||
@Service
|
||||
//@Service
|
||||
public class DbLogRecordServiceImpl implements LogRecordApi {
|
||||
|
||||
/**
|
||||
|
@ -38,7 +39,8 @@ public class DbLogRecordServiceImpl implements LogRecordApi {
|
|||
/**
|
||||
* 日志记录 service接口
|
||||
*/
|
||||
private final SysLogService sysLogService;
|
||||
@Resource
|
||||
private SysLogService sysLogService;
|
||||
|
||||
/**
|
||||
* 异步记录日志用的线程池
|
||||
|
@ -50,6 +52,7 @@ public class DbLogRecordServiceImpl implements LogRecordApi {
|
|||
*/
|
||||
private final LogRefreshManager logRefreshManager;
|
||||
|
||||
|
||||
public DbLogRecordServiceImpl(LogManagerThreadPool logManagerThreadPool, SysLogService sysLogService) {
|
||||
this.logManagerThreadPool = logManagerThreadPool;
|
||||
this.sysLogService = sysLogService;
|
||||
|
|
|
@ -31,7 +31,7 @@ import static cn.stylefeng.roses.kernel.log.api.constants.LogFileConstants.FILE_
|
|||
* @author fengshuonan
|
||||
* @date 2020/10/28 14:52
|
||||
*/
|
||||
@Service
|
||||
//@Service
|
||||
public class FileLogRecordServiceImpl implements LogRecordApi {
|
||||
|
||||
private final LogManagerThreadPool logManagerThreadPool;
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
<artifactId>log-sdk-db</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>log-sdk-file</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,9 +1,20 @@
|
|||
package cn.stylefeng.roses.kernel.log.starter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import cn.stylefeng.roses.kernel.log.api.expander.LogConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.log.api.pojo.log.SysLogProperties;
|
||||
import cn.stylefeng.roses.kernel.log.api.threadpool.LogManagerThreadPool;
|
||||
import cn.stylefeng.roses.kernel.log.db.DbLogRecordServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.log.db.service.impl.SysLogServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.log.file.FileLogRecordServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.log.modular.requestapi.aop.RequestApiLogRecordAop;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 日志的自动配置
|
||||
* 系统日志的自动配置
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/1 17:12
|
||||
|
@ -11,4 +22,46 @@ import org.springframework.context.annotation.Configuration;
|
|||
@Configuration
|
||||
public class GunsLogAutoConfiguration {
|
||||
|
||||
public static final String SYS_LOG_PREFIX = "sys-log";
|
||||
public static final String SYS_LOG_TYPE_DEFAULT = "db";
|
||||
|
||||
/**
|
||||
* 系统日志的的配置
|
||||
*
|
||||
* @author liuhanqing
|
||||
* @date 2020/12/20 14:17
|
||||
*/
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = SYS_LOG_PREFIX)
|
||||
public SysLogProperties sysLogProperties() {
|
||||
return new SysLogProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* 每个请求接口记录日志的AOP
|
||||
* 根据配置文件初始化日志记录器
|
||||
* 日志存储类型:db-数据库,file-文件,默认存储在数据库中
|
||||
*
|
||||
* @author liuhanqing
|
||||
* @date 2020/12/20 13:02
|
||||
*/
|
||||
@Bean
|
||||
public RequestApiLogRecordAop requestApiLogRecordAop(SysLogProperties sysLogProperties) {
|
||||
if (StrUtil.isBlank(sysLogProperties.getType())) {
|
||||
return new RequestApiLogRecordAop(new DbLogRecordServiceImpl(new LogManagerThreadPool(), new SysLogServiceImpl()));
|
||||
}else{
|
||||
if(!SYS_LOG_TYPE_DEFAULT.equals(sysLogProperties.getType())){
|
||||
//修改为从sys_config中获取日志存储位置
|
||||
String fileSavePath = "";
|
||||
if (SystemUtil.getOsInfo().isWindows()) {
|
||||
fileSavePath = LogConfigExpander.getLogFileSavePathWindows();
|
||||
}else{
|
||||
fileSavePath = LogConfigExpander.getLogFileSavePathLinux();
|
||||
}
|
||||
//sysLogProperties.getFileSavePath()
|
||||
return new RequestApiLogRecordAop(new FileLogRecordServiceImpl(fileSavePath, new LogManagerThreadPool()));
|
||||
}
|
||||
}
|
||||
return new RequestApiLogRecordAop(new DbLogRecordServiceImpl(new LogManagerThreadPool(), new SysLogServiceImpl()));
|
||||
}
|
||||
}
|
|
@ -330,6 +330,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户
|
||||
*
|
||||
* @param userId
|
||||
* @return java.lang.String
|
||||
* @author wangle
|
||||
* @date 2020/12/17 18:11
|
||||
*/
|
||||
@Override
|
||||
public String getNameByUserId(Long userId) {
|
||||
SysUser sysUser = this.getById(userId);
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
throw new SystemModularException(SysUserExceptionEnum.USER_NOT_EXIST);
|
||||
}
|
||||
return sysUser.getRealName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserLoginInfoDTO getUserLoginInfo(String account) {
|
||||
UserLoginInfoDTO userLoginInfoDTO = new UserLoginInfoDTO();
|
||||
|
|
Loading…
Reference in New Issue