zoukankan      html  css  js  c++  java
  • springboot1.5.4 log4j

    resources下面添加:

    log4j.properties:

    #
    log4j.rootCategory=INFO, stdout, file, errorfile
    log4j.category.com.ddd=INFO, dddfile
    log4j.logger.error=errorfile
    
    # 控制台输出
    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} %5p %c{1}:%L - %m%n
    
    # root日志输出
    log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.file.file=logs/ebways-spot-order-all.log
    log4j.appender.file.DatePattern='.'yyyy-MM-dd
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
    
    # error日志输出
    log4j.appender.errorfile=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.errorfile.file=logs/ebways-spot-order-error.log
    log4j.appender.errorfile.DatePattern='.'yyyy-MM-dd
    log4j.appender.errorfile.Threshold = ERROR
    log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout
    log4j.appender.errorfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
    
    # com.ddd下的日志输出
    log4j.appender.dddfile=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.dddfile.file=logs/ebways-spot-order-my.log
    log4j.appender.dddfile.DatePattern='.'yyyy-MM-dd
    log4j.appender.dddfile.layout=org.apache.log4j.PatternLayout
    log4j.appender.dddfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L ---- %m%n

    pom文件:

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.4.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.7</java.version>
            <druid.version>1.1.2</druid.version>
        </properties>
    
        <dependencies>
            <!-- spring boot start -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
            <!-- log4j -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-log4j</artifactId>
                <version>1.3.8.RELEASE</version>
            </dependency>

    controller类:

    import org.apache.log4j.Logger;
    
    private static final Logger log = Logger.getLogger(TestController.class);

    即可生成log文件:

  • 相关阅读:
    EL表达式遍历方法之一
    django auth认证
    总结五个在办公中使用很爽的软件
    django所遇到问题简单总结
    django 远程数据库mysql migrate失败报error 1045之 解决方案
    深拷贝和浅拷贝之地址改变
    序列表转换成横向菜单
    Pycharm破解
    css里涉及到定位相关的example实例
    记录求职
  • 原文地址:https://www.cnblogs.com/gmq-sh/p/7660735.html
Copyright © 2011-2022 走看看