Linux 日志打印到文件的2种方式
生活随笔
收集整理的這篇文章主要介紹了
Linux 日志打印到文件的2种方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 打印日志到httx/logs/out.log中,日志一直累加,需要跑定時任務半夜1點切割日志。 如下:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="info" monitorInterval="30"><Properties><Property name="log_path">/httx/logs</Property></Properties><!-- appender配置 --><Appenders><File name="LogOut" fileName="${log_path}/out.log"filePermissions="rw-r--r--"><PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %t %c.%M - %m%n" /></File></Appenders><!-- logger配置 --><Loggers><Root level="info"><AppenderRef ref="LogOut" /></Root></Loggers> </Configuration>2. 打印日志到httx/logs/out.log中,日志按照天寫入文件中。 如下:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="info" monitorInterval="30"><Properties><Property name="log_path">/httx/logs</Property> </Properties><!-- appender配置 --> <Appenders><Console name="Console" target="SYSTEM_OUT"><PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%t] %c.%M - %m%n"/></Console><!--DEBUG級別日志--><RollingRandomAccessFile name="Debug" fileName="${log_path}/debug.log"filePattern="${log_path}/debug.log%d{yyyy-MM-dd}-%i"><PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%t %l] %c.%M - %m%n"/><Policies><TimeBasedTriggeringPolicy/><SizeBasedTriggeringPolicy size="300MB"/></Policies></RollingRandomAccessFile><!--INFO級別日志--><RollingRandomAccessFile name="Info" fileName="${log_path}/info.log"filePattern="${log_path}/debug.log%d{yyyy-MM-dd}-%i"><PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%t %l] %c.%M - %m%n"/><Filters><ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/><ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/></Filters><Policies><TimeBasedTriggeringPolicy/><SizeBasedTriggeringPolicy size="300MB"/></Policies></RollingRandomAccessFile><!-- ERORR級別日志 --><RollingRandomAccessFile name="Error" fileName="${log_path}/error.log"filePattern="${log_path}/warn.log%d{yyyy-MM-dd}-%i"><PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p] [%t %l] %c.%M - %m%n"/><Policies><TimeBasedTriggeringPolicy/><SizeBasedTriggeringPolicy size="300MB"/></Policies><Filters><ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/></Filters></RollingRandomAccessFile><!--配置日志寫到文件--><RollingRandomAccessFile name="out" fileName="${log_path}/out.log"filePattern="${log_path}/out.log%d{yyyy-MM-dd}-%i"><PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %t %l %c.%M - %m%n"/><Policies><TimeBasedTriggeringPolicy/><SizeBasedTriggeringPolicy size="300MB"/></Policies></RollingRandomAccessFile><Async name="Async"><AppenderRef ref="Console"/><AppenderRef ref="Info"/><AppenderRef ref="Error"/><AppenderRef ref="out"/></Async></Appenders><Loggers><Root level="info"><AppenderRef ref="Console"/><AppenderRef ref="Info"/><AppenderRef ref="Error"/><AppenderRef ref="out"/><!--異步配置--><!--<AppenderRef ref="Async"/>--></Root> </Loggers></Configuration>?
?
總結
以上是生活随笔為你收集整理的Linux 日志打印到文件的2种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java家电售后管理系统计算机毕业设计M
- 下一篇: Linux vsFTPd服务详解——vs