环境:IntelliJ IDEA 2022.2,jdk8
插件要求:Settings-->Plugins中安装lomkob插件
pom依赖项:
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.22</version>
</dependency>
向application.yml添加如下内容:
logging: config: classpath:logback.xml
resources项目文件夹下新建logback.xml(似乎删掉也能用。。。那log日志记录到哪里的文件里去了?):
1 <?xml version="1.0" encoding="UTF-8"?> 2 <configuration> 3 4 <!-- 格式化输出:%date表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %msg:日志消息,%n是换行符--> 5 <property name="LOG_PATTERN" 6 value="[%d{yyyy-MM-dd HH\:mm\:ss}] [%p] [%c] %m%n" /> 7 8 <!-- 日志输出路径 --> 9 <!-- 当前项目下的 logs文件夹 --> 10 <property name="FILE_PATH" value="${user.dir}/logs/%d{yyyy-MM-dd}.%i.log" /> 11 12 <!-- 控制台输出日志 --> 13 <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> 14 <encoder> 15 <!-- 按照上面配置的LOG_PATTERN来打印日志 --> 16 <pattern>${LOG_PATTERN}</pattern> 17 </encoder> 18 </appender> 19 20 <!--每天生成一个日志文件,保存30天的日志文件。rollingFile是用来切分文件的 --> 21 <appender name="rollingFile" 22 class="ch.qos.logback.core.rolling.RollingFileAppender"> 23 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 24 <fileNamePattern> 25 ${FILE_PATH} 26 </fileNamePattern> 27 <!-- keep 30 days' worth of history --> 28 <maxHistory>30</maxHistory> 29 <timeBasedFileNamingAndTriggeringPolicy 30 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> 31 <!-- 日志文件的最大大小 --> 32 <maxFileSize>10MB</maxFileSize> 33 </timeBasedFileNamingAndTriggeringPolicy> 34 </rollingPolicy> 35 36 <encoder> 37 <pattern>${LOG_PATTERN}</pattern> 38 </encoder> 39 </appender> 40 41 <!-- 日志输出级别 --> 42 <!-- 级别大于 info 的都会记录--> 43 <root level="INFO" > 44 <appender-ref ref="console" /> 45 <appender-ref ref="rollingFile" /> 46 </root> 47 </configuration>View Code
配置项似乎不需要如下几个:
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.21</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.21</version> </dependency><dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.1.7</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.7</version> </dependency>
标签:插件,qos,21,配置,slf4j,使用,org,logback From: https://www.cnblogs.com/Ocean-MondoPaco/p/17044634.html