GithubHelp home page GithubHelp logo

siathalysedi / logger-spring-boot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rozidan/logger-spring-boot

0.0 2.0 0.0 103 KB

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

License: Apache License 2.0

Java 100.00%

logger-spring-boot's Introduction

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

logger-spring-boot's People

Contributors

rozidan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.