EN
Log4j2 - automatic injection with Lombok
7
points
In this short article, we would like to show how to get access to Log4j2 with @Log4j2
Lombok annotation.
Practical example:
package example.controllers;
import lombok.extern.log4j.Log4j2; // <------ REQUIRED!
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
@Log4j2 // <--------------------------------- REQUIRED!
@Controller
public class ExampleController {
@RequestMapping(value = "/path/to/api", method = RequestMethod.GET)
@ResponseBody
public String getIndex(HttpServletRequest request) {
log.info("Logger test..."); // <----- USAGE EXAMPLE!
return "OK!";
}
}