springboot中如何整合log4g2

这篇文章主要介绍了跳羚中如何整合log4g2,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下 。1.导入jar
跳羚默认是用日志记录的日志框架的,所以需要排除日志记录,不然会出现冲突依赖冲突的报错 。groupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId排除!-去掉跳羚默认配置-groupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-log/artifactId依赖性!-引入log4j2依赖-groupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-log4j 2/artifactId/依赖性
2.配置文件 1 .如果自定义了文件名,需要在application.yml中配置2.默认名log4j2-spring.xml,就省下了在application.yml中配置在applicaiton.yaml中添加配置#日志文件config :类路径:日志4g 2 。可扩展置标语言com 。阿里巴巴 。nacos 。客户 。配置 。impl :警告cn 。杰 。恢复tor : tr
ace
file:
#${file.name} 后期可以改成${spring.application.name}
path: /log/${file.name}
file:
name: dome
【springboot中如何整合log4g2】在config中配置log4g2.xml文件
?xml version= 1.0encoding= UTF-8 ?!-- status= OFF ,可以去掉,它的含义为是否记录log4j2本身的event信息,默认是OFF --configuration status= offmonitorInterval= 60!-- properties --!-- property name= projectName --!-- riiot--!-- /property --!-- /properties --appenders!-- 开发环境用 --Console name= debug_consoletarget= SYSTEM_OUTPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n /FiltersThresholdFilter level= DEBUG /ThresholdFilter level= INFOonMatch= DENYonMismatch= NEUTRAL //Filters/ConsoleConsole name= consoletarget= SYSTEM_OUTPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n /FiltersThresholdFilter level= info //Filters/Console!-- 输出日志到文件 每天一个文件(ERROR-FATAL级别) --RollingRandomAccessFile name= AppErrorDailyRollingFilefileName= ${sys:LOG_PATH}/AppError.logappend= truebufferedIO= falsebufferSize= 256filePattern= ${sys:LOG_PATH}/AppError.log.%d{yyyy-MM-dd}.logPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n/FiltersThresholdFilter level= ERROR //FiltersPoliciesTimeBasedTriggeringPolicy modulate= trueinterval= 1 //Policies/RollingRandomAccessFile!-- 输出日志到文件 每天一个文件(WARN级别) --RollingRandomAccessFile name= AppWarnDailyRollingFilefileName= ${sys:LOG_PATH}/AppWarn.logappend= truebufferedIO= truebufferSize= 10240immediateFlush= falsefilePattern= ${sys:LOG_PATH}/AppWarn.log.%d{yyyy-MM-dd}.logPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n/FiltersThresholdFilter level= WARN /ThresholdFilter level= ERRORonMatch= DENYonMismatch= NEUTRAL //FiltersPoliciesTimeBasedTriggeringPolicy modulate= trueinterval= 1 //Policies/RollingRandomAccessFile!-- 输出日志到文件 每天一个文件(INFO级别) --RollingRandomAccessFile name= AppInfoDailyRollingFilefileName= ${sys:LOG_PATH}/AppAccess.logappend= truebufferedIO= truebufferSize= 409600immediateFlush= falsefilePattern= ${sys:LOG_PATH}/AppAccess.log.%d{yyyy-MM-dd}.logPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n/FiltersThresholdFilter level= INFO /ThresholdFilter level= WARNonMatch= DENYonMismatch= NEUTRAL //FiltersPoliciesTimeBasedTriggeringPolicy modulate= trueinterval= 1 //Policies/RollingRandomAccessFile!-- 输出日志到文件 每天一个文件(INFO级别) --RollingRandomAccessFile name= DBAccessDailyRollingFilefileName= ${sys:LOG_PATH}/DBAccess.logappend= truebufferedIO= truebufferSize= 409600immediateFlush= falsefilePattern= ${sys:LOG_PATH}/DBAccess.log.%d{yyyy-MM-dd}.logPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n/FiltersThresholdFilter level= INFO /ThresholdFilter level= WARNonMatch= DENYonMismatch= NEUTRAL //FiltersPoliciesTimeBasedTriggeringPolicy modulate= trueinterval= 1 //Policies/RollingRandomAccessFile!-- 输出日志到文件 每天一个文件(ERROR级别) --RollingRandomAccessFile name= DBErrorDailyRollingFilefileName= ${sys:LOG_PATH}/DBError.logappend= truebufferedIO= falsebufferSize= 256filePattern= ${sys:LOG_PATH}/DBError.log.%d{yyyy-MM-dd}.logPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n/FiltersThresholdFilter level= WARN //FiltersPoliciesTimeBasedTriggeringPolicy modulate= trueinterval= 1 //Policies/RollingRandomAccessFile!-- 输出日志到文件 每天一个文件(ERROR级别) --RollingRandomAccessFile name= SysErrorDailyRollingFilefileName= ${sys:LOG_PATH}/SysError.logappend= truebufferedIO= falsefilePattern= ${sys:LOG_PATH}/SysError.log.%d{yyyy-MM-dd}.logPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n/FiltersThresholdFilter level= WARN //FiltersPoliciesTimeBasedTriggeringPolicy modulate= trueinterval= 1 //Policies/RollingRandomAccessFile!-- 启动日志 --RollingRandomAccessFile name= BootLogfileName= ${sys:LOG_PATH}/Boot.logappend= falsebufferedIO= falsefilePattern= ${sys:LOG_PATH}/Boot.log.%d{yyyy-MM-dd}.logPatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [%t] {%c}-%m%n/FiltersThresholdFilter level= INFO //FiltersPoliciesTimeBasedTriggeringPolicy modulate= trueinterval= 1 //Policies/RollingRandomAccessFile!--Kafka name= SyncKafkatopic= logssyncSend= falsePatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [riiot] [${jar.name}] [%X{ip}] [dev] [%t] {%c}-%m /Property name= bootstrap.servers 192.168.1.49:9092 /PropertyProperty name= acks 0 /PropertyProperty name= compression.type gzip /PropertyProperty name= max.block.ms 10000 /PropertyFiltersThresholdFilter level= INFO //Filters/Kafka! ndash; 异步发送kafkandash;Async name= KafkabufferSize= 512blocking= falseAppenderRef ref= SyncKafka //AsyncKafka name= KafkaErrLogtopic= errLogTopicsyncSend= falsePatternLayout pattern= [%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%traceId] [riiot] [${jar.name}] [%X{ip}] [dev] [%t] {%c}-%m /Property name= bootstrap.servers 192.168.1.49:9092 /PropertyProperty name= acks 0 /PropertyProperty name= compression.type gzip /PropertyFiltersThresholdFilter level= ERROR //Filters/Kafka! ndash; 异步发送kafkandash;Async name= AsyncKafkaErrLogbufferSize= 512blocking= falseAppenderRef ref= KafkaErrLog //Async/appendersloggers!-- 只把包名是com.cmsr的日志输出到文件 --logger name= com.cmsradditivity= falselevel= debugappender-ref ref= AppErrorDailyRollingFile/appender-ref ref= AppWarnDailyRollingFile/appender-ref ref= AppInfoDailyRollingFile/appender-ref ref= console/appender-ref ref= debug_console//logger!-- 只把包名是com.cmsr.sicp.common.mybatis(DB正常执行,异常分别写到不同的log文件)的日志输出到文件 --logger name= com.cmsr.sicp.common.mybatisadditivity= falselevel= debugappender-ref ref= DBAccessDailyRollingFile/appender-ref ref= DBErrorDailyRollingFile/appender-ref ref= console//logger!-- 过滤springframework输出,提高启动速度 (生产环境中需要整体删除)--logger name= org.springframeworkadditivity= falselevel= warnappender-ref ref= console//logger!-- 启动日志单独输出 --logger name= com.cmsr.Launcheradditivity= falselevel= infoappender-ref ref= BootLog/appender-ref ref= console//logger!-- 定义全局 。其他包的日志只输出到控制台,不输出到日志文件 --root level= errorappender-ref ref= SysErrorDailyRollingFile/appender-ref ref= console//root/loggers/configuration

推荐阅读