使用properties配置log4j2.生成種類日誌並按天儲存檔案
阿新 • • 發佈:2019-01-28
log4j2.properties.直接放在resources下面就行了,程式自己會匹配
status = error dest = err name = PropertiesConfig #公共變數 #檔案路徑 property.filePath=logs property.filePattern=logs/%d{yyyy}/%d{MM} #輸出格式 property.layoutPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %p ] [ %c ] %m%n # 級別過濾(過濾日誌記錄) #filters = threshold filter.threshold.type = ThresholdFilter # 只記錄debug級別以上的日誌,大小寫無關:(ALL<)TRACE<DEBUG<INFO<WARN<ERROR<FATAL(<OFF) filter.threshold.level = debug # 根記錄器,所有記錄器的父輩 rootLogger.level = debug appender.console.type = Console appender.console.name = STDOUT appender.console.target = SYSTEM_OUT appender.console.layout.type = PatternLayout appender.console.layout.pattern = ${layoutPattern} rootLogger.appenderRef.stdout.ref = STDOUT appender.D.type = RollingFile appender.D.name = DebugRollingFile appender.D.fileName = ${filePath}/opdata-debug.log appender.D.filePattern = ${filePattern}/opdata_debug.log appender.D.layout.type = PatternLayout appender.D.layout.pattern = ${layoutPattern} appender.D.policies.type = Policies appender.D.policies.time.type = TimeBasedTriggeringPolicy appender.D.policies.time.interval = 1 appender.D.policies.time.modulate = true appender.D.policies.size.type = SizeBasedTriggeringPolicy appender.D.policies.size.size=20M appender.D.strategy.type = DefaultRolloverStrategy appender.D.strategy.max = 100 #過濾debug以上資訊 appender.D.filter.threshold.type = ThresholdFilter appender.D.filter.threshold.level = INFO appender.D.filter.threshold.onMatch = DENY appender.D.filter.threshold.onMisMatch=NEUTRAL rootLogger.appenderRef.D.ref=DebugRollingFile rootLogger.appenderRef.D.level=debug appender.I.type = RollingFile appender.I.name = InfoRollingFile appender.I.fileName = ${filePath}/opdata-info.log appender.I.filePattern = ${filePattern}/opdata_info.log appender.I.layout.type = PatternLayout appender.I.layout.pattern = ${layoutPattern} appender.I.policies.type = Policies appender.I.policies.time.type = TimeBasedTriggeringPolicy appender.I.policies.time.interval = 1 appender.I.policies.time.modulate = true appender.I.policies.size.type = SizeBasedTriggeringPolicy appender.I.policies.size.size=20M appender.I.strategy.type = DefaultRolloverStrategy appender.I.strategy.max = 100 #過濾INFO以上資訊 appender.I.filter.threshold.type = ThresholdFilter appender.I.filter.threshold.level = WARN appender.I.filter.threshold.onMatch = DENY appender.I.filter.threshold.onMisMatch=NEUTRAL rootLogger.appenderRef.I.ref = InfoRollingFile rootLogger.appenderRef.I.level=INFO appender.W.type = RollingFile appender.W.name = WarnRollingFile appender.W.fileName = ${filePath}/opdata-warn.log appender.W.filePattern = ${filePattern}/opdata_warn.log appender.W.layout.type = PatternLayout appender.W.layout.pattern = ${layoutPattern} appender.W.policies.type = Policies appender.W.policies.time.type = TimeBasedTriggeringPolicy appender.W.policies.time.interval = 1 appender.W.policies.time.modulate = true appender.W.policies.size.type = SizeBasedTriggeringPolicy appender.W.policies.size.size=20M appender.W.strategy.type = DefaultRolloverStrategy appender.W.strategy.max = 100 #過濾warn以上資訊 appender.W.filter.threshold.type = ThresholdFilter appender.W.filter.threshold.level = ERROR appender.W.filter.threshold.onMatch = DENY appender.W.filter.threshold.onMisMatch=NEUTRAL rootLogger.appenderRef.W.ref = WarnRollingFile rootLogger.appenderRef.W.level=WARN appender.E.type = RollingFile appender.E.name = ErrorRollingFile appender.E.fileName = ${filePath}/opdata-error.log appender.E.filePattern = ${filePattern}/opdata_error.log appender.E.layout.type = PatternLayout appender.E.layout.pattern = ${layoutPattern} appender.E.policies.type = Policies appender.E.policies.time.type = TimeBasedTriggeringPolicy appender.E.policies.time.interval = 1 appender.E.policies.time.modulate = true appender.E.policies.size.type = SizeBasedTriggeringPolicy appender.E.policies.size.size=20M appender.E.strategy.type = DefaultRolloverStrategy appender.E.strategy.max = 100 #過濾ERROR以上資訊 appender.E.filter.threshold.type = ThresholdFilter appender.E.filter.threshold.level = FATAL appender.E.filter.threshold.onMatch = DENY appender.E.filter.threshold.onMisMatch=NEUTRAL rootLogger.appenderRef.E.ref = ErrorRollingFile rootLogger.appenderRef.E.level=ERROR appender.F.type = RollingFile appender.F.name = FatalRollingFile appender.F.fileName = ${filePath}/opdata-fatal.log appender.F.filePattern = ${filePattern}/opdata_fatal.log appender.F.layout.type = PatternLayout appender.F.layout.pattern = ${layoutPattern} appender.F.policies.type = Policies appender.F.policies.time.type = TimeBasedTriggeringPolicy appender.F.policies.time.interval = 1 appender.F.policies.time.modulate = true appender.F.policies.size.type = SizeBasedTriggeringPolicy appender.F.policies.size.size=20M appender.F.strategy.type = DefaultRolloverStrategy appender.F.strategy.max = 100 rootLogger.appenderRef.F.ref = FatalRollingFile rootLogger.appenderRef.F.level=FATAL #appender.S.type = Socket #appender.S.name= SocketTCP #appender.S.host = 10.10.1.169 #appender.S.port=4560 #appender.S.protocol = TCP #appender.S.layout.type = JsonLayout #appender.S.layout.compact = true #appender.S.layout.eventEol = true #appender.S.connectTimeoutMillis = 2000 #rootLogger.appenderRef.S.ref=SocketTCP #rootLogger.appenderRef.S.level=socket #配置第三方包的日誌 logger.jpath.name=com.jayway.jsonpath logger.jpath.level=error logger.mongodb.name=org.mongodb.driver logger.mongodb.level=error