企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
直接去看成体系的资料https://www.kancloud.cn/dahuzichengxuyuan/java-jvm 其实就是在业务当中进行日志打点 也可以收集整个项目的各种级别的日志 这里我们提供这次项目使用到的logback-spring.xml配置文件: ### ``` <?xml version="1.0" encoding="UTF-8" ?> <configuration> <appender name="consoleApp" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern> %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n </pattern> </layout> </appender> <appender name="dataApp" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <encoder> <pattern> `%date{yyyy-MM-dd HH:mm:ss.SSS}`%msg`%n </pattern> </encoder> <!-- 滚动策略 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 路径 --> <fileNamePattern>app_log/log/app.data.%d.log</fileNamePattern> <MaxHistory>1</MaxHistory> </rollingPolicy> </appender> <appender name="fileInfoApp" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <onMatch>DENY</onMatch> <onMismatch>ACCEPT</onMismatch> </filter> <encoder> <pattern> %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n </pattern> </encoder> <!-- 滚动策略 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 路径 --> <fileNamePattern>app_log/log/app.info.%d.log</fileNamePattern> <MaxHistory>1</MaxHistory> </rollingPolicy> </appender> <appender name="fileErrorApp" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>ERROR</level> </filter> <encoder> <pattern> %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n </pattern> </encoder> <!-- 设置滚动策略 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 路径 --> <fileNamePattern>app_log/log/app.err.%d.log</fileNamePattern> <!-- 控制保留的归档文件的最大数量,超出数量就删除旧文件,假设设置每个月滚动, 且<maxHistory> 是1,则只保存最近1个月的文件,删除之前的旧文件 --> <MaxHistory>1</MaxHistory> </rollingPolicy> </appender> <!--用于统计数据--> <logger name="dataLogger"> <level value="INFO" /> <appender-ref ref="dataApp" /> </logger> <root level="INFO"> <appender-ref ref="consoleApp"/> <appender-ref ref="fileInfoApp"/> <appender-ref ref="fileErrorApp"/> </root> </configuration> ``` ### 这只是其中一种写法 仅供参考 ###