# LLog
**Repository Path**: lboot/LLog
## Basic Information
- **Project Name**: LLog
- **Description**: 轻量级日志监控组件,集成管理面板,支持多条件查询检索
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 7
- **Forks**: 1
- **Created**: 2023-10-30
- **Last Updated**: 2025-05-28
## Categories & Tags
**Categories**: logging
**Tags**: Java, 日志, SpringBoot
## README
Lucy
不断迭代的技术解决方案
---
LLog
## 简介
`LLog`是基于`AOP`构建的请求日志记录和查询工具库,通过引入该工具库,完成配置,实现对接口请求日志的记录、查询检索等功能。
- [x] 请求状态、时间、来源、耗时,请求参数,响应结果,作用接口记录
- [x] 支持与鉴权服务结合,记录请求来源为用户ID
- [x] 通过注解参数配置,实现对请求或响应数据的加密处理
- [x] 支持多条件组合查询,支持参数模糊查询,时间排序
- [x] 记录异常堆栈,接口异常
- [x] 自动加入`trace_id`,实现调用链条的追踪
- [x] 不限制日志格式
- [ ] 计划支持微服务调用栈展示...

## 准备
在引入任何 `Lucy`系列依赖之前,需要完成`jitpack`镜像仓库的配置。
```xml
jitpack.io
https://www.jitpack.io
```
## 集成
### 引入
在`pom`中引入,版本号与[发行版本](https://gitee.com/lboot/LLog/releases)一致。
```xml
com.gitee.lboot
LLog
0.0.8
```
### 配置
#### 1. 白名单配置
`LLog`日志管理页面访问,默认仅支持 `127.0.0.1`的请求来源访问(即支持本地访问),如果需要支持更多的访问来源,需要配置放行`IP`列表,通过`,`分隔。
```properties
# 日志请求白名单
llog.ip.allows=127.0.0.1,198.0.0.1
```
#### 2. 数据库配置
`LLog`基于`lucy-jpa`构建数据库访问,需要完成对应数据库配置。
```properties
# MySQL
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/demo?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai
spring.datasource.username=demo
spring.datasource.password=
# JPA 允许结构替换
spring.main.allow-bean-definition-overriding=true
# 最小空闲连接数量
spring.datasource.hikari.minimum-idle=5
# 最长生命周期
spring.datasource.hikari.max-lifetime=120000
# 空闲连接存活最大时间,默认600000(10分钟)
spring.datasource.hikari.idle-timeout=50000
# 连接池最大连接数,默认是10
spring.datasource.hikari.maximum-pool-size=20
# 此属性控制从池返回的连接的默认自动提交行为,默认值:true
spring.datasource.hikari.auto-commit=true
# 连接测试查询
spring.datasource.hikari.connection-test-query=SELECT 1
# jpa 配置
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false
spring.jpa.database=MYSQL
#自动将驼峰命名转换为小写和下划线 userId -> user_id
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#不加这句则默认为myisam引擎
spring.jpa.database-platform= org.hibernate.dialect.MySQL5InnoDBDialect
```
#### 3. 鉴权方案配置
`LLog`会记录用户ID和请求IP。如果需要获取到用户ID,则需要完成对鉴权服务的配置,拓展实现`AuthService`中的`isLogin`和`getUid`接口,或者直接引入`lucy-rbac`等实现方案。
**推荐自定义实现**
```java
@Slf4j
@Service
@AllArgsConstructor
public class DemoAuthServiceImpl implements AuthService {
@Override
public Boolean isLogin() {
// return StpUtil.isLogin(); // 使用 SaToken
return AuthService.super.isLogin();
}
@Override
public String getUid() {
// return StpUtil.getLoginIdAsString(); // 使用 SaToken
return null;
}
}
```
## 使用
### @ApiLog
通过自定义注解标记需要记录请求日志的接口,实现对接口请求的自动记录。
```java
@ApiLog("追踪测试")
@GetMapping("trace")
@ApiOperation(value = "追踪ID测试")
public ResponseDTO