Springboot: log4j集成,配合lombok

Posted gaomanito

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于Springboot: log4j集成,配合lombok的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot 集成Log4j

SpringBoot集成log4j

springboot集成log4j + sql打印日志

springboot项目集成logf4j详细流程记录

springBoot log4j集成的mybatis 控制台打印sql

SpringBoot-集成Log4j2