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:
xxxxxxxxxx
1
package example.controllers;
2
3
import lombok.extern.log4j.Log4j2; // <------ REQUIRED!
4
import org.springframework.http.MediaType;
5
import org.springframework.http.ResponseEntity;
6
import org.springframework.stereotype.Controller;
7
import org.springframework.web.bind.annotation.RequestMapping;
8
import org.springframework.web.bind.annotation.RequestMethod;
9
import org.springframework.web.bind.annotation.ResponseBody;
10
11
import javax.servlet.http.HttpServletRequest;
12
13
// <--------------------------------- REQUIRED!
14
15
public class ExampleController {
16
17
value = "/path/to/api", method = RequestMethod.GET) (
18
19
public String getIndex(HttpServletRequest request) {
20
21
log.info("Logger test..."); // <----- USAGE EXAMPLE!
22
23
return "OK!";
24
}
25
}