This tutorial shows how to use Lombok's @Slf4j Annotation to work with Slf4J.
This Annotation automatically generates following code so that we don't have to repeat it in every Class we want to log
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExampleOther.class);
Application Schema [Results]
Spring Boot Starters
Create Project: springboot_log_lombok (add Spring Boot Starters from the table)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside controllers package)
MyController.java
package com.ivoronline.springboot_log_lombok.controllers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
@Slf4j
@Controller
public class MyController {
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
log.info("Hello from Controller");
return "Hello from Controller";
}
}