提交 c3a6f85c 编写于 作者: Q qinyingjie

fix:添加日志

上级 e78d61a0
...@@ -4,6 +4,7 @@ import com.kwan.springbootkwan.entity.User; ...@@ -4,6 +4,7 @@ import com.kwan.springbootkwan.entity.User;
import com.kwan.springbootkwan.service.IUserService; import com.kwan.springbootkwan.service.IUserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -16,6 +17,7 @@ import java.util.List; ...@@ -16,6 +17,7 @@ import java.util.List;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2022/12/19 16:08 * @date : 2022/12/19 16:08
*/ */
@Slf4j
@Api(description = "用户信息", tags = "UserController") @Api(description = "用户信息", tags = "UserController")
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/user")
...@@ -27,6 +29,7 @@ public class UserController { ...@@ -27,6 +29,7 @@ public class UserController {
@ApiOperation(value = "获取所有用户", notes = "获取所有用户") @ApiOperation(value = "获取所有用户", notes = "获取所有用户")
@RequestMapping(value = "/all", method = RequestMethod.GET) @RequestMapping(value = "/all", method = RequestMethod.GET)
public List<User> addAdvertise() { public List<User> addAdvertise() {
log.info("测试日志={}", "success");
return userService.getUsers(); return userService.getUsers();
} }
......
...@@ -44,3 +44,7 @@ mybatis-plus: ...@@ -44,3 +44,7 @@ mybatis-plus:
logic-delete-value: 1 logic-delete-value: 1
logic-not-delete-value: 0 logic-not-delete-value: 0
table-underline: true table-underline: true
#logger配置
logging:
config: classpath:logback-spring.xml
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<!-- 此xml在spring-boot-1.5.3.RELEASE.jar里 -->
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<!--控制台打印日志,不需要配置appender了-->
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<!-- 开启后可以通过jmx动态控制日志级别(springboot Admin的功能) -->
<!--<jmxConfigurator/>-->
<!--总日志-->
<appender name="ALL-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--日志存放路径-->
<file>../logs/springboot-mybatis.log</file>
<encoder>
<!-- pattern节点,用来设置日志的输入格式 -->
<pattern>%date [%level] [%thread] %logger{60} [%file : %line] %msg%n</pattern>
<!--文件编码格式-->
<charset>UTF-8</charset>
</encoder>
<!-- 滚动策略 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 添加.gz 历史日志会启用压缩 大大缩小日志文件所占空间 -->
<fileNamePattern>../logs/springboot-mybatis.log.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 保留30天日志 -->
<maxHistory>30</maxHistory>
<!--文件最大存储-->
<totalSizeCap>10GB</totalSizeCap>
</rollingPolicy>
</appender>
<!--错误日志-->
<appender name="ERROR-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--日志存放路径-->
<file>../logs/error.log</file>
<encoder>
<pattern>%date [%level] [%thread] %logger{60} [%file : %line] %msg%n</pattern>
<!--文件编码格式-->
<charset>UTF-8</charset>
</encoder>
<!-- 滚动策略 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 添加.gz 历史日志会启用压缩 大大缩小日志文件所占空间 -->
<fileNamePattern>../logs/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 保留30天日志 -->
<maxHistory>30</maxHistory>
<!--文件最大存储-->
<totalSizeCap>10GB</totalSizeCap>
</rollingPolicy>
<!-- 过滤日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<!-- 用于配置符合过滤条件的操作 -->
<onMatch>ACCEPT</onMatch>
<!-- 用于配置不符合过滤条件的操作 -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<logger name="com.kwan.springbootkwan" level="INFO"/>
<root level="INFO">
<!--控制台打印日志-->
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ALL-FILE"/>
<appender-ref ref="ERROR-FILE"/>
</root>
</configuration>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册