log4j2 demo mysql_Log4j2 日志性能之巅

Log4j2的性能测试

90bc9ffcaaf00fd6fd28a4100e0be65a.png

从图中不难看出,在线程数为 2~16 之间,混合使用同步和异步的logger来打印日志,性能是最好的。2/ 目标

混合 sync/async

彩色日志

分类输出到不同文件

自动压缩日志文件并归档

69169ef30defcf6f9e9f4816314c6929.png

与Spring Boot集成的Maven 依赖 pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/ma ... gt%3B

4.0.0

org.spring

springboot

0.0.1-SNAPSHOT

jar

springboot

Demo Log4j2 for Spring Boot

org.springframework.boot

spring-boot-starter-parent

1.5.4.RELEASE

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-logging

org.projectlombok

lombok

1.16.16

org.springframework.boot

spring-boot-starter-log4j2

com.lmax

disruptor

3.3.6

org.springframework.boot

spring-boot-maven-plugin

配置 Log4j2,在 resources 文件目录下添加文件 log4j2.xml,会被自动配置

/Users/admin/Code/log

/Users/admin/Code/log/7z

????

%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx

filePattern="${fileGz}/$${date:yyyy-MM}/%d{yyyy-MM-dd}-%i.web-info.gz">

filePattern="${fileGz}/$${date:yyyy-MM}/%d{yyyy-MM-dd}-%i.web-error.gz">

添加 Application 启动类

@SpringBootApplication

@EnableScheduling

public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

}

}

添加测试的 Job 类

@Component

@Log4j2

public class LogJob {

/**

* 2秒钟执行1次

*/

@Scheduled(fixedRate = 2 * 1000)

public void logging(){

Date now = new Date();

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

log.info(simpleDateFormat.format(now));

log.debug("-------DEBUG---------");

log.error(now.getTime());

}

}

大致文件目录结构

306f25d504af04c64348ef6f785f47e0.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值