统一日志打印

https://github.com/rozidan/logger-spring-boot

Setup

In order to add logger to your project simply add this dependency to your classpath:

<dependency>
    <groupId>com.github.rozidan</groupId>
    <artifactId>logger-spring-boot</artifactId>
    <version>1.1.0</version>
</dependency>

For snapshots versions add the sonatype public repository:

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/groups/public" }
    ...
}

Log your application

Apply the Logger to your application with annotation in a configuration class:@EnableLogger

@Configuration
@EnableLogger
public class LoggerConfig {
​
}

Simply add the annotation to a method, or to a class scope:@Loggable

@RestController
@RequestMapping(path = "/employees")
public class EmployeeController {
    
    @Loggable
    @GetMapping
    public List<EmployeeDto> listAllEmployees() {
    }
}

More examples:

Warning whenever execution is over 2 sec:

@Loggable(warnOver = 2, warnUnit = TimeUnit.SECONDS)

This will result 2 lines of log, one where 2 sec are over, and the other when execution is complete:

.....c.i.s.l.w.c.EmployeeController           : #listAllEmployees([]): in PT2.833S and still running (max PT0.002S)
.....c.i.s.l.w.c.EmployeeController           : #listAllEmployees([]): [] in PT6.345S (max PT0.002S)

Log when enter to a method:

@Loggable(entered = true)

Skip printing arguments and results of a method:

@Loggable(skipArgs = true, skipResult = true)

Log with different level (default is INFO):

@Loggable(LogLevel.WARN)

Set a different logger name (default is class name):

@Loggable(value = LogLevel.WARN, name = "my-logger-name")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

A-ezra

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值