zoukankan      html  css  js  c++  java
  • Java程序中的Log文件配置

    log4j.properties文件

    log4j.rootLogger=info,stdout,logfile
    
    #stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%p]-[%C %M %L]-%m%n
    
    #logfile
    log4j.appender.logfile=org.apache.log4j.RollingFileAppender
    log4j.appender.logfile.File=/usr/local/logs/xx.log
    log4j.appender.logfile.MaxFileSize=128MB
    log4j.appender.logfile.MaxBackupIndex=100
    log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
    log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%p]-[%C %M %L]-%m%n

    =======================================

    Spring和log4j结合

    <!-- 属性注入器,用于读取项目配置文件中的属性 -->
    <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean" id="configProperties">
      <property name="locations">
        <list>
          <value>classpath*:log4j.properties</value>
        </list>
      </property>
    </bean>

    三种方式:
    第一种(Log):

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
            
    private static Log log = LogFactory.getLog(XXX.class);
    log.info("**");

    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
    </dependency>



    第二种(Log4J):

    import org.apache.log4j.Logger;
    
    private static Logger log = Logger.getLogger(XXX.class);
    log.info("**");

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>



    第三种(slf4j):

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    private static final Logger log = LoggerFactory.getLogger(XXX.class);
    log.info("**");
    
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.0</version>
    </dependency>
  • 相关阅读:
    laravel 安装及入门
    mysql事务处理的意义
    PHP项目:如何用PHP高并发检索数据库?
    inner join、left join、right join等的区别
    百度地图引入网页中
    google地图引入网页
    thinkphp的mvc理解
    SpringBoot+Shiro入门小栗子
    Springboot+WebSocket+Kafka(写着玩的)
    Windows下安装单机Kafka
  • 原文地址:https://www.cnblogs.com/atomicbomb/p/6609581.html
Copyright © 2011-2022 走看看