zoukankan      html  css  js  c++  java
  • springboot下的logback-spring配置文件以及使用方式

    基于sprigboot的日志模板

    <?xml version="1.0" encoding="UTF-8"?>

    <!-- For assistance related to logback-translator or configuration -->
    <!-- files in general, please contact the logback user mailing list -->
    <!-- at http://www.qos.ch/mailman/listinfo/logback-user -->
    <!-- -->
    <!-- For professional support please see -->
    <!-- http://www.qos.ch/shop/products/professionalSupport -->
    <!-- -->
    <configuration>
    <!-- 获取applicaiton.yml中的log地址 -->
    <springProperty scope="context" name="LOG_HOME" source="logging.file.path"/>
    <springProperty scope="context" name="LOG_NAME" source="logging.file.name"/>
    <!-- Errors were reported during translation. -->
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
    <pattern>%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n</pattern>
    </encoder>
    </appender>
    <!-- 文件日志策略:每天生成一个日志文件,保存30天的日志文件-->
    <appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
    <fileNamePattern>${LOG_HOME}/${LOG_NAME}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
    <maxFileSize>100MB</maxFileSize>
    <maxHistory>30</maxHistory>
    <totalSizeCap>10GB</totalSizeCap>
    <cleanHistoryOnStart>true</cleanHistoryOnStart>
    </rollingPolicy>
    <encoder>
    <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} | %msg%n</pattern> 
    </encoder>
    </appender>
    <!-- level : TRACE < DEBUG < INFO < WARN < ERROR -->
    <root level="INFO">
    <appender-ref ref="stdout"/>
    <appender-ref ref="debug"/>
    </root>

    </configuration>




    application.yml
    logging.file.path (在未指定绝对路径的情况下,默认与启动服务同级目录)

    java使用方式:

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    Logger logger = LoggerFactory.getLogger(IceDataController.class);

    logger.info("test:"+resMessage);


    jar包依赖:
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>


  • 相关阅读:
    iOS开发~UI布局(二)storyboard中autolayout和size class的使用详解
    iOS开发~UI布局(一)初探Size Class
    OC登陆界面登陆按钮动画
    Git学习 --> 个人常用命令add,commit以及push
    Git使用之设置SSH Key
    【iOS开发】多屏尺的自动适配 AutoLayout (纯代码方式)
    iOS网络检测Reachability 使用 Demo,可检测2、3、4G
    iOS提醒用户进入设置界面进行重新授权通知定位等功能
    iOS中 @synthesize 和 @dynamic 区别
    iOS 开发笔记
  • 原文地址:https://www.cnblogs.com/zf-crazy/p/14138767.html
Copyright © 2011-2022 走看看