整合slf4j+log4j2

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   sp   檔案   on   div   

所需要的包:

log4j-api,
log4j-core,
log4j-slf4j-impl,
slf4j-api


設定檔位置:將log4j2.xml放到resources下
配置內容:
<?xml version="1.0" encoding="UTF-8"?><configuration status="DEBUG">    <!--先定義所有的appender-->    <appenders>        <!--這個輸出控制台的配置-->        <Console name="Console" target="SYSTEM_OUT">            <!--控制台只輸出level及以上層級的資訊(onMatch),其他的直接拒絕(onMismatch)-->            <ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>            <!--這個都知道是輸出日誌的格式-->            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>        </Console>        <!--這個會列印出所有的資訊,每次大小超過size,則這size大小的日誌會自動存入按年份-月份建立的檔案夾下面並進行壓縮,作為存檔-->        <RollingFile name="RollingFile" fileName="logs/akka.log"                     filePattern="logs/$${date:yyyy-MM}/akka-%d{MM-dd-yyyy}-%i.log">            <PatternLayout pattern="%d{yyyy-MM-dd ‘at‘ HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>            <SizeBasedTriggeringPolicy size="100MB"/>        </RollingFile>    </appenders>    <!--然後定義logger,只有定義了logger並引入的appender,appender才會生效-->    <loggers>        <!--建立一個預設的root的logger-->        <root level="debug">            <appender-ref ref="RollingFile"/>            <appender-ref ref="Console"/>        </root>    </loggers></configuration>

大功告成!

整合slf4j+log4j2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.