Springboot logger annotation

'A Spring Boot `@Loggable` logger annotation'

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

com.github.rozidan
ArtifactId

ArtifactId

logger-spring-boot
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Springboot logger annotation
'A Spring Boot `@Loggable` logger annotation'
Project URL

Project URL

https://github.com/rozidan/logger-spring-boot.git
Project Organization

Project Organization

Idan Rozenfeld
Source Code Management

Source Code Management

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

Download logger-spring-boot

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.rozidan/logger-spring-boot/ -->
<dependency>
    <groupId>com.github.rozidan</groupId>
    <artifactId>logger-spring-boot</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.rozidan/logger-spring-boot/
implementation 'com.github.rozidan:logger-spring-boot:1.1.0'
// https://jarcasting.com/artifacts/com.github.rozidan/logger-spring-boot/
implementation ("com.github.rozidan:logger-spring-boot:1.1.0")
'com.github.rozidan:logger-spring-boot:jar:1.1.0'
<dependency org="com.github.rozidan" name="logger-spring-boot" rev="1.1.0">
  <artifact name="logger-spring-boot" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.rozidan', module='logger-spring-boot', version='1.1.0')
)
libraryDependencies += "com.github.rozidan" % "logger-spring-boot" % "1.1.0"
[com.github.rozidan/logger-spring-boot "1.1.0"]

Dependencies

runtime (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-aop jar

Project Modules

There are no modules declared in this project.

Spring Boot Logger

A Spring Boot @Loggable annotation that will help you log your application more easily.

Base on jcabi-aspects project @Loggable annotation.

Build Status Coverage Status

Maven Central Sonatype Nexus (Snapshots)

License

Features

Register the Logger to your Spring Boot application and allow it to log wherever you tell it to. The Logger uses the slf4j to support abstraction for various logging frameworks.

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>
compile 'com.github.rozidan:logger-spring-boot:1.1.0'

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 @EnableLogger annotation in a configuration class:

@Configuration
@EnableLogger
public class LoggerConfig {

}

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

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

License

Apache-2.0

Versions

Version
1.1.0