Springboot查看日志

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

即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值