Springboot查看日志
以前用springMVC时查看日志直接进入tail -f ****.out,但是用了springboot之后,一时不知道如何实现,记录一下
以下以log4j2为日志框架
先在log4j2.xml中添加如下配置
<RollingFile name="RollingFileConsole" fileName="./logs/console.out"
filePattern="./logs/$${date:yyyy-MM}/console-%d{yyyy-MM-dd}-%i.out">
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="500 MB"/>
</Policies>
</RollingFile>
其中
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
是限定日志取那些级别写入文件,可以根据需求灵活应变
然后
<!--然后定义logger,只有定义了logger并引入的appender,appender才会生效-->
<loggers>
<!--过滤掉spring和mybatis的一些无用的DEBUG信息-->
<logger name="com.qthl.wf.dao" level="debug" additivity="false">
<appender-ref ref="RollingFileConsole"/>
</logger>
<root level="info">
<appender-ref ref="RollingFileConsole"/>
</root>
</loggers>
查看的时候直接
tail -f **/console.out
即可