zoukankan      html  css  js  c++  java
  • log4配置

    log4j 和 log4j2

    方式一:log4j2.xml

    添加 jar 包

    1     <!-- log4j-core -->
    2     <!-- 
    3     <dependency>
    4         <groupId>org.apache.logging.log4j</groupId>
    5         <artifactId>log4j-core</artifactId>
    6         <version>2.6.2</version>
    7     </dependency>

    文件配置:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <Configuration>
     3     <Appenders>
     4         <Console name="STDOUT" target="SYSTEM_OUT">
     5             <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
     6         </Console>
     7     </Appenders>
     8     <Loggers>
     9         <Logger name="com.opensymphony.xwork2" level="debug"/>
    10         <Logger name="org.apache.struts2" level="debug"/>
    11         <Root level="warn">
    12             <AppenderRef ref="STDOUT"/>
    13         </Root>
    14     </Loggers>
    15 </Configuration>

    方式二:log4j.properties

    添加 jar 包

    1     <!-- log4j -->
    2     <dependency>
    3         <groupId>log4j</groupId>
    4         <artifactId>log4j</artifactId>
    5         <version>1.2.17</version>
    6     </dependency>

    文件配置:

    ### direct log messages to stdout ###
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Target=System.out
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    
    ### direct messages to file mylog.log ###
    log4j.appender.file=org.apache.log4j.FileAppender
    log4j.appender.file.File=c:/mylog.log
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    
    ### set log levels - for more verbose logging change 'info' to 'debug' ###
    
    log4j.rootLogger=info, stdout
  • 相关阅读:
    SPA项目开发之动态树以及数据表格和分页
    SPA项目开发之首页导航左侧菜单栏
    SPA项目开发之登录
    使用vue-cli搭建spa项目
    Splay 平衡树
    主席树(可持久化线段树 )
    P3195 [HNOI2008]玩具装箱TOY
    P2962 [USACO09NOV]灯Lights
    【hdu4405】AeroplaneChess
    HDU3853:LOOPS
  • 原文地址:https://www.cnblogs.com/yjq520/p/7008559.html
Copyright © 2011-2022 走看看