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"
·
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>
更多推荐
已为社区贡献1条内容
所有评论(0)