• Springboot: log4j集成,配合lombok


            //排除默认的
         <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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId> <version>1.3.8.RELEASE</version> </dependency>

          <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
          </dependency>

    log4j.properties文件

    log4j.rootLogger=INFO,Console,File
    log4j.appender.Console=org.apache.log4j.ConsoleAppender
    log4j.appender.Console.Target=System.out
    log4j.appender.Console.layout=org.apache.log4j.PatternLayout
    log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n
    log4j.appender.File=org.apache.log4j.RollingFileAppender
    log4j.appender.File.File=logs/ssm.log
    log4j.appender.File.MaxFileSize=10MB
    log4j.appender.File.Threshold=ALL
    log4j.appender.File.layout=org.apache.log4j.PatternLayout
    log4j.appender.File.layout.ConversionPattern=[%p] [%d{yyyy-MM-dd HH:mm:ss}][%c]%m%n

    使用

    @RestController
    @RequestMapping("/demo")
    @Slf4j
    public class DemoController {
        @RequestMapping(value = "/test", method = {RequestMethod.GET, RequestMethod.POST})
        public String test() {
            log.info("测试方法");
            return "hello,this is zhngxian's demo";
        }
    }
    https://blog.csdn.net/IT_hejinrong/article/details/89148860
  • 相关阅读:
    ES6模块
    遍历数组和对象的方法
    JVM知识(六):linux环境下查看JVM内存大小
    WebSocket实时消息推送
    SpringBoot中基于Mybatis多数据源操作
    浅谈Redis中的雪崩和穿透及击穿。
    Hibernate与Mybatis的区别
    Java动态代理和反射机制
    JSON对象和JSON字符串的区别
    JVM知识(五):垃圾回收算法
  • 原文地址:https://www.cnblogs.com/gaomanito/p/10952211.html
Copyright © 2020-2023  润新知