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")