mirror of https://gitee.com/stylefeng/roses
【log】整理log模块,文件日志读取管理问题修改
parent
6de9145036
commit
ce2510192b
|
@ -28,4 +28,14 @@ public interface LogConstants {
|
||||||
*/
|
*/
|
||||||
String LOG_DEFAULT_APP_NAME = "none-app-name";
|
String LOG_DEFAULT_APP_NAME = "none-app-name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认查询日志分页
|
||||||
|
*/
|
||||||
|
Integer DEFAULT_BEGIN_PAGE_NO = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认查询日志分页大小
|
||||||
|
*/
|
||||||
|
Integer DEFAULT_PAGE_SIZE = 10;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package cn.stylefeng.roses.kernel.log.api.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志存储的方式,数据库还是文件
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2020/12/24 14:08
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum LogSaveTypeEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储到数据库
|
||||||
|
*/
|
||||||
|
DB("db"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储到文件
|
||||||
|
*/
|
||||||
|
FILE("file");
|
||||||
|
|
||||||
|
LogSaveTypeEnum(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import cn.stylefeng.roses.kernel.log.db.service.SysLogService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -28,7 +27,6 @@ import java.util.List;
|
||||||
* @date 2020/11/2 17:40
|
* @date 2020/11/2 17:40
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
|
||||||
public class DbLogManagerServiceImpl implements LogManagerApi {
|
public class DbLogManagerServiceImpl implements LogManagerApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,14 +165,15 @@ public class DbLogManagerServiceImpl implements LogManagerApi {
|
||||||
* @date 2020/11/3 11:20
|
* @date 2020/11/3 11:20
|
||||||
*/
|
*/
|
||||||
private void createDefaultLogManagerParam(LogManagerParam logManagerParam) {
|
private void createDefaultLogManagerParam(LogManagerParam logManagerParam) {
|
||||||
|
|
||||||
// 默认从第一页开始
|
// 默认从第一页开始
|
||||||
if (logManagerParam.getPageNo() == null) {
|
if (logManagerParam.getPageNo() == null) {
|
||||||
logManagerParam.setPageNo(1);
|
logManagerParam.setPageNo(DEFAULT_BEGIN_PAGE_NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 默认每页10条
|
// 默认每页10条
|
||||||
if (logManagerParam.getPageSize() == null) {
|
if (logManagerParam.getPageSize() == null) {
|
||||||
logManagerParam.setPageSize(10);
|
logManagerParam.setPageSize(DEFAULT_PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 开始时间为空则用当天时间开始时间
|
// 开始时间为空则用当天时间开始时间
|
||||||
|
|
|
@ -3,13 +3,13 @@ package cn.stylefeng.roses.kernel.log.file;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
import cn.stylefeng.roses.kernel.log.api.LogManagerApi;
|
import cn.stylefeng.roses.kernel.log.api.LogManagerApi;
|
||||||
import cn.stylefeng.roses.kernel.log.api.exception.LogException;
|
import cn.stylefeng.roses.kernel.log.api.exception.LogException;
|
||||||
import cn.stylefeng.roses.kernel.log.api.pojo.manage.LogManagerParam;
|
import cn.stylefeng.roses.kernel.log.api.pojo.manage.LogManagerParam;
|
||||||
import cn.stylefeng.roses.kernel.log.api.pojo.record.LogRecordDTO;
|
import cn.stylefeng.roses.kernel.log.api.pojo.record.LogRecordDTO;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -21,6 +21,8 @@ import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.stylefeng.roses.kernel.log.api.constants.LogConstants.DEFAULT_BEGIN_PAGE_NO;
|
||||||
|
import static cn.stylefeng.roses.kernel.log.api.constants.LogConstants.DEFAULT_PAGE_SIZE;
|
||||||
import static cn.stylefeng.roses.kernel.log.api.constants.LogFileConstants.FILE_CONTRACT_SYMBOL;
|
import static cn.stylefeng.roses.kernel.log.api.constants.LogFileConstants.FILE_CONTRACT_SYMBOL;
|
||||||
import static cn.stylefeng.roses.kernel.log.api.constants.LogFileConstants.FILE_SUFFIX;
|
import static cn.stylefeng.roses.kernel.log.api.constants.LogFileConstants.FILE_SUFFIX;
|
||||||
import static cn.stylefeng.roses.kernel.log.api.exception.enums.LogExceptionEnum.*;
|
import static cn.stylefeng.roses.kernel.log.api.exception.enums.LogExceptionEnum.*;
|
||||||
|
@ -70,14 +72,20 @@ public class FileLogManagerServiceImpl implements LogManagerApi {
|
||||||
|
|
||||||
// 文件当前指针
|
// 文件当前指针
|
||||||
long filePointer = 0L;
|
long filePointer = 0L;
|
||||||
|
if (logManagerParam.getPageNo() == null) {
|
||||||
|
logManagerParam.setPageNo(DEFAULT_BEGIN_PAGE_NO);
|
||||||
|
} else {
|
||||||
// 如果页数不等于1,则根据当前登陆用户信息取出上次读取文件的位置
|
// 如果页数不等于1,则根据当前登陆用户信息取出上次读取文件的位置
|
||||||
if (!logManagerParam.getPageNo().equals(1)) {
|
if (!DEFAULT_BEGIN_PAGE_NO.equals(logManagerParam.getPageNo())) {
|
||||||
Object pointer = LoginContext.me().getLoginUser().getOtherInfos().get("filePointer");
|
Object pointer = LoginContext.me().getLoginUser().getOtherInfos().get("filePointer");
|
||||||
if (ObjectUtil.isNotEmpty(pointer)) {
|
if (ObjectUtil.isNotEmpty(pointer)) {
|
||||||
filePointer = (long) pointer;
|
filePointer = (long) pointer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (logManagerParam.getPageSize() == null) {
|
||||||
|
logManagerParam.setPageSize(DEFAULT_PAGE_SIZE);
|
||||||
|
}
|
||||||
// 返回分页结果
|
// 返回分页结果
|
||||||
PageResult<LogRecordDTO> pageResult = new PageResult<>();
|
PageResult<LogRecordDTO> pageResult = new PageResult<>();
|
||||||
pageResult.setPageSize(logManagerParam.getPageSize());
|
pageResult.setPageSize(logManagerParam.getPageSize());
|
||||||
|
|
|
@ -2,11 +2,15 @@ package cn.stylefeng.roses.kernel.log.starter;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.system.SystemUtil;
|
import cn.hutool.system.SystemUtil;
|
||||||
|
import cn.stylefeng.roses.kernel.log.api.LogManagerApi;
|
||||||
|
import cn.stylefeng.roses.kernel.log.api.enums.LogSaveTypeEnum;
|
||||||
import cn.stylefeng.roses.kernel.log.api.expander.LogConfigExpander;
|
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.pojo.log.SysLogProperties;
|
||||||
import cn.stylefeng.roses.kernel.log.api.threadpool.LogManagerThreadPool;
|
import cn.stylefeng.roses.kernel.log.api.threadpool.LogManagerThreadPool;
|
||||||
|
import cn.stylefeng.roses.kernel.log.db.DbLogManagerServiceImpl;
|
||||||
import cn.stylefeng.roses.kernel.log.db.DbLogRecordServiceImpl;
|
import cn.stylefeng.roses.kernel.log.db.DbLogRecordServiceImpl;
|
||||||
import cn.stylefeng.roses.kernel.log.db.service.impl.SysLogServiceImpl;
|
import cn.stylefeng.roses.kernel.log.db.service.impl.SysLogServiceImpl;
|
||||||
|
import cn.stylefeng.roses.kernel.log.file.FileLogManagerServiceImpl;
|
||||||
import cn.stylefeng.roses.kernel.log.file.FileLogRecordServiceImpl;
|
import cn.stylefeng.roses.kernel.log.file.FileLogRecordServiceImpl;
|
||||||
import cn.stylefeng.roses.kernel.log.modular.requestapi.aop.RequestApiLogRecordAop;
|
import cn.stylefeng.roses.kernel.log.modular.requestapi.aop.RequestApiLogRecordAop;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
@ -22,8 +26,10 @@ import org.springframework.context.annotation.Configuration;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class GunsLogAutoConfiguration {
|
public class GunsLogAutoConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志配置的前缀
|
||||||
|
*/
|
||||||
public static final String SYS_LOG_PREFIX = "sys-log";
|
public static final String SYS_LOG_PREFIX = "sys-log";
|
||||||
public static final String SYS_LOG_TYPE_DEFAULT = "db";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统日志的的配置
|
* 系统日志的的配置
|
||||||
|
@ -42,26 +48,59 @@ public class GunsLogAutoConfiguration {
|
||||||
* 根据配置文件初始化日志记录器
|
* 根据配置文件初始化日志记录器
|
||||||
* 日志存储类型:db-数据库,file-文件,默认存储在数据库中
|
* 日志存储类型:db-数据库,file-文件,默认存储在数据库中
|
||||||
*
|
*
|
||||||
|
* @param sysLogProperties 系统日志配置文件
|
||||||
* @author liuhanqing
|
* @author liuhanqing
|
||||||
* @date 2020/12/20 13:02
|
* @date 2020/12/20 13:02
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public RequestApiLogRecordAop requestApiLogRecordAop(SysLogProperties sysLogProperties) {
|
public RequestApiLogRecordAop requestApiLogRecordAop(SysLogProperties sysLogProperties) {
|
||||||
if (StrUtil.isBlank(sysLogProperties.getType())) {
|
|
||||||
return new RequestApiLogRecordAop(new DbLogRecordServiceImpl(new LogManagerThreadPool(), new SysLogServiceImpl()));
|
// 如果类型是文件
|
||||||
} else {
|
if (StrUtil.isNotBlank(sysLogProperties.getType())
|
||||||
if (!SYS_LOG_TYPE_DEFAULT.equals(sysLogProperties.getType())) {
|
&& LogSaveTypeEnum.FILE.getCode().equals(sysLogProperties.getType())) {
|
||||||
//修改为从sys_config中获取日志存储位置
|
|
||||||
|
// 修改为从sys_config中获取日志存储位置
|
||||||
String fileSavePath = "";
|
String fileSavePath = "";
|
||||||
if (SystemUtil.getOsInfo().isWindows()) {
|
if (SystemUtil.getOsInfo().isWindows()) {
|
||||||
fileSavePath = LogConfigExpander.getLogFileSavePathWindows();
|
fileSavePath = LogConfigExpander.getLogFileSavePathWindows();
|
||||||
} else {
|
} else {
|
||||||
fileSavePath = LogConfigExpander.getLogFileSavePathLinux();
|
fileSavePath = LogConfigExpander.getLogFileSavePathLinux();
|
||||||
}
|
}
|
||||||
//sysLogProperties.getFileSavePath()
|
|
||||||
return new RequestApiLogRecordAop(new FileLogRecordServiceImpl(fileSavePath, new LogManagerThreadPool()));
|
return new RequestApiLogRecordAop(new FileLogRecordServiceImpl(fileSavePath, new LogManagerThreadPool()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// 其他情况用数据库存储日志
|
||||||
return new RequestApiLogRecordAop(new DbLogRecordServiceImpl(new LogManagerThreadPool(), new SysLogServiceImpl()));
|
return new RequestApiLogRecordAop(new DbLogRecordServiceImpl(new LogManagerThreadPool(), new SysLogServiceImpl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志管理器
|
||||||
|
*
|
||||||
|
* @param sysLogProperties 系统日志配置文件
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2020/12/20 18:53
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public LogManagerApi logManagerApi(SysLogProperties sysLogProperties) {
|
||||||
|
|
||||||
|
// 如果类型是文件
|
||||||
|
if (StrUtil.isNotBlank(sysLogProperties.getType())
|
||||||
|
&& LogSaveTypeEnum.FILE.getCode().equals(sysLogProperties.getType())) {
|
||||||
|
|
||||||
|
// 修改为从sys_config中获取日志存储位置
|
||||||
|
String fileSavePath = "";
|
||||||
|
if (SystemUtil.getOsInfo().isWindows()) {
|
||||||
|
fileSavePath = LogConfigExpander.getLogFileSavePathWindows();
|
||||||
|
} else {
|
||||||
|
fileSavePath = LogConfigExpander.getLogFileSavePathLinux();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FileLogManagerServiceImpl(fileSavePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他情况用数据库存储日志
|
||||||
|
return new DbLogManagerServiceImpl();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package cn.stylefeng.roses.kernel.system.modular.user.factory;
|
package cn.stylefeng.roses.kernel.system.modular.user.factory;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.lang.Dict;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||||
|
@ -108,6 +109,9 @@ public class LoginUserFactory {
|
||||||
// 填充应用信息
|
// 填充应用信息
|
||||||
loginUser.setApps(appsByAppCodes);
|
loginUser.setApps(appsByAppCodes);
|
||||||
|
|
||||||
|
// 日志系统问题 默认初始化其他信息 dict
|
||||||
|
loginUser.setOtherInfos(new Dict());
|
||||||
|
|
||||||
return loginUser;
|
return loginUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue