【log】整理log模块引用,根据配置文件初始化不同的日记记录器

pull/3/head
liuhq 2020-12-20 15:16:07 +08:00 committed by fengshuonan
parent 983c909aad
commit ac94d92218
7 changed files with 659 additions and 557 deletions

View File

@ -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";
}

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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>

View File

@ -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()));
}
}

View File

@ -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();