2、配置日志格式
This commit is contained in:
@@ -47,6 +47,11 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- Druid 数据库连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/$$ /$$ /$$ /$$ /$$
|
||||
| $$ / $$|__/ |__/ | $$
|
||||
| $$/ $$/ /$$ /$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$$$$$$| $$$$$$$ /$$ /$$
|
||||
\ $$$$/ | $$ |____ $$ /$$__ $$| $$ | $$| $$ /$$_____/| $$__ $$| $$ | $$
|
||||
>$$ $$ | $$ /$$$$$$$| $$ \ $$| $$ | $$| $$| $$$$$$ | $$ \ $$| $$ | $$
|
||||
/$$/\ $$| $$ /$$__ $$| $$ | $$| $$ | $$| $$ \____ $$| $$ | $$| $$ | $$
|
||||
| $$ \ $$| $$| $$$$$$$| $$$$$$/| $$$$$$$| $$ /$$$$$$$/| $$ | $$| $$$$$$/
|
||||
|__/ |__/|__/ \_______/ \______/ \____ $$|__/|_______/ |__/ |__/ \______/
|
||||
/$$ | $$
|
||||
| $$$$$$/
|
||||
\______/
|
||||
|
||||
One-stop focus on the whole network hotspot.
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
author: 刑加一
|
||||
email: 2294931964@qq.com
|
||||
about me: https://blog.crushtj.top
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
@@ -1,14 +1,53 @@
|
||||
server:
|
||||
port: 18881
|
||||
servlet:
|
||||
context-path: /xiaoyishu-auth
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# 数据库连接信息
|
||||
url: jdbc:mysql://10.0.0.3:3306/xiaoyishu?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
username: xiaoyi
|
||||
password: HhpxE2HWE4bGTyB5
|
||||
password: Os0TpcErSh26nT4Nqqjgo2vwi3IaEglzj+brT2b7q0P4Dlhnv3OEQVUNpG/dYqvJZUCR2/IyfxQ4LnQIB7FcfQ==
|
||||
druid: # Druid 连接池
|
||||
initial-size: 5 # 初始化连接池大小
|
||||
min-idle: 5 # 最小连接池数量
|
||||
max-active: 100 # 最大连接池数量
|
||||
max-wait: 60000 # 连接时最大等待时间(单位:毫秒)
|
||||
test-while-idle: true
|
||||
time-between-eviction-runs-millis: 60000 # 配置多久进行一次检测,检测需要关闭的连接(单位:毫秒)
|
||||
min-evictable-idle-time-millis: 300000 # 配置一个连接在连接池中最小生存的时间(单位:毫秒)
|
||||
max-evictable-idle-time-millis: 900000 # 配置一个连接在连接池中最大生存的时间(单位:毫秒)
|
||||
validation-query: SELECT 1 FROM DUAL # 配置测试连接是否可用的查询 sql
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
pool-prepared-statements: false
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/* # 配置监控后台访问路径
|
||||
login-username: admin # 配置监控后台登录的用户名、密码
|
||||
login-password: admin
|
||||
filter:
|
||||
config:
|
||||
enabled: true
|
||||
stat:
|
||||
enabled: true
|
||||
log-slow-sql: true # 开启慢 sql 记录
|
||||
slow-sql-millis: 2000 # 若执行耗时大于 2s,则视为慢 sql
|
||||
merge-sql: true
|
||||
wall: # 防火墙
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
connection-properties: config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAK6C4nQHNuYSebx/5vOdvDqP/o8AH+p73s1LWCFs915RiwVHvtEd+ropmXkCO3Agc9Zuo8pyMvccIgPL9F0I8YkCAwEAAQ==
|
||||
output:
|
||||
ansi:
|
||||
enabled: always
|
||||
application:
|
||||
name: xiaoyishu-auth
|
||||
|
||||
logging:
|
||||
level:
|
||||
top.crushtj.xiaoyishu.auth.domain.mappers: debug
|
||||
mybatis-plus:
|
||||
mapper-locations:
|
||||
- classpath*:top/crushtj/**/*.xml # 匹配所有模块中的 Mapper XML 文件
|
||||
@@ -16,3 +55,11 @@ mybatis-plus:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true # 开启驼峰命名转换
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 日志输出(调试用)
|
||||
|
||||
logging:
|
||||
level:
|
||||
top.crushtj.xiaoyishu.auth.domain.mappers: debug
|
||||
config: classpath:config/logback-dev.xml
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<jmxConfigurator/>
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
|
||||
<!-- 应用名称 -->
|
||||
<property scope="context" name="appName" value="xiaoyishu"/>
|
||||
<property name="CONSOLE_LOG_PATTERN"
|
||||
value="[%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){cyan}] [%thread] [%clr(%-5level){highlight}] %clr(%logger{50}){magenta} - %msg%n"/>
|
||||
|
||||
|
||||
<springProfile name="dev">
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<withJansi>true</withJansi>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
</configuration>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<jmxConfigurator/>
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
|
||||
<!-- 应用名称 -->
|
||||
<property scope="context" name="appName" value="xiaoyishu"/>
|
||||
<!-- 自定义日志输出路径,以及日志名称前缀 -->
|
||||
<property name="LOG_FILE" value="/var/log/xiaoyishu/${appName}.%d{yyyy-MM-dd}"/>
|
||||
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"/>
|
||||
<!--<property name="CONSOLE_LOG_PATTERN" value="${FILE_LOG_PATTERN}"/>-->
|
||||
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件输出的文件名 -->
|
||||
<FileNamePattern>${LOG_FILE}-%i.log</FileNamePattern>
|
||||
<!-- 日志文件保留天数 -->
|
||||
<MaxHistory>30</MaxHistory>
|
||||
<!-- 日志文件最大的大小 -->
|
||||
<TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</TimeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!-- 格式化输出:%d 表示日期,%thread 表示线程名,%-5level:级别从左显示 5 个字符宽度 %errorMessage:日志消息,%n 是换行符-->
|
||||
<pattern>${FILE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- prod 环境(仅输出到文件中) -->
|
||||
<springProfile name="prod">
|
||||
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
||||
<root level="INFO">
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
</configuration>
|
||||
@@ -0,0 +1,40 @@
|
||||
package top.crushtj.xiaoyishu.auth;
|
||||
|
||||
import com.alibaba.druid.filter.config.ConfigTools;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* @author hanfuye
|
||||
* @version V1.0
|
||||
* @Title: DruidTest
|
||||
* @Description:
|
||||
* @date 2025/12/01
|
||||
*/
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class DruidTest {
|
||||
|
||||
/**
|
||||
* Druid 密码加密
|
||||
*/
|
||||
@Test
|
||||
@SneakyThrows
|
||||
void testEncodePassword() {
|
||||
// 你的密码
|
||||
String password = "HhpxE2HWE4bGTyB5";
|
||||
String[] arr = ConfigTools.genKeyPair(512);
|
||||
|
||||
// 私钥
|
||||
log.info("privateKey: {}", arr[0]);
|
||||
// 公钥
|
||||
log.info("publicKey: {}", arr[1]);
|
||||
|
||||
// 通过私钥加密密码
|
||||
String encodePassword = ConfigTools.encrypt(arr[0], password);
|
||||
log.info("password: {}", encodePassword);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package top.crushtj.xiaoyishu.auth;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -31,4 +32,12 @@ class XiaoyiAuthApplicationTests {
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryTest(){
|
||||
LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(UserEntity::getUsername, "刑加一");
|
||||
UserEntity user = userMapper.selectOne(queryWrapper);
|
||||
log.info("查询结果:{}", user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user