乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Log4j2的XML和properties配置方式

       昵稱27831725 2017-11-15

      1、把log4j2相關(guān)的jar包導(dǎo)入到WEB-INF的lib目錄下
      log4j-api-2.6.2.jar
      log4j-core-2.6.2.jar
      2、在src目錄下添加log4j2的配置文件
      (1)log4j2.xml配置文件,以下是一個(gè)把日志輸出到控制臺(tái)和保存在文件中的配置文件

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="warn" name="MyApp">
          <appenders>
              <Console name="Console" target="SYSTEM_OUT">    
                  <ThresholdFilter level="debug"/>    
                  <PatternLayout pattern="%m%n"/>    
              </Console>    
              <File name="log" fileName="e:\\test1.log" append="true">
                  <ThresholdFilter level="error"/>
                  <PatternLayout pattern="%d-%m%n"/>    
              </File>  
          </appenders>
      
          <loggers>
              <root level="debug">
                  <appender-ref ref="Console"></appender-ref>
                  <appender-ref ref="log"></appender-ref>
              </root>
          </loggers>
      </Configuration>

      如果需要復(fù)雜一些的請(qǐng)參考:http://www.cnblogs.com/hanfight/p/5721855.html

      (2)log4j2.properties配置文件,功能同上

      status = warn
      name = MyApp
      
      filter.threshold.type = ThresholdFilter
      filter.threshold.level = debug
      
      appender.console.type = Console
      appender.console.name = STDOUT
      appender.console.layout.type = PatternLayout
      appender.console.layout.pattern = %m%n
      
      appender.rolling.type = File
      appender.rolling.name = log
      appender.rolling.append = true
      appender.rolling.fileName = e:\\test1.log
      appender.rolling.layout.type = PatternLayout
      appender.rolling.layout.pattern = %d-%m%n
      
      rootLogger.level = debug
      rootLogger.appenderRef.stdout.ref = STDOUT
      rootLogger.appenderRef.log.ref = log

      如果需要復(fù)雜的請(qǐng)參考:
      http://logging./log4j/2.x/manual/configuration.html#Properties

      注:.properties這種方式用的比較少,鏈接中的注釋也比較少,請(qǐng)參考(1)中的文檔,對(duì)照著理解和編寫。

      3、輸出log日志并記錄成文件

      //1.定義Logger對(duì)象,用Logger.getLogger(Class clazz):
      public static Logger log4jDemo1 = LogManager.getLogger(LogListener.class.getName());
      
      //2.定義Logger對(duì)象,用LogManager.getLogger(Class clazz):
      //public static Logger log4jDemo2 = LogManager.getLogger(LogListener.class);
      
      //3.定義Logger對(duì)象,用LogManager.getLogger(String name):
      //public static Logger log4jDemo3 = LogManager.getLogger(LogListener.class.getName());
      
      //4.定義Logger對(duì)象,將3中的name變成具體的字符串:
      //public static Logger log4jDemo4 = LogManager.getLogger("common.LogListener");
      
      log4jDemo1.debug("我是debug");
      log4jDemo1.error("我是error");
      log4jDemo1.log(Level.ERROR, "我是Level.ERROR ");
      • 文件名log4j2.properties
      • private static Logger log=(Logger) LogManager.getLogger(Loger4jlisentr.class.getName());

      • public void attributeAdded(ServletContextAttributeEvent arg0) { log.debug("添加了一個(gè)application屬性!屬性名稱為="+arg0.getName()+"值為: "+arg0.getValue()); log.error("沒(méi)有報(bào)錯(cuò),這是測(cè)試!1234567890"); }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多