Languages
[Edit]
EN

Log4j2 - automatic injection with Lombok

7 points
Created by:
MMORex
600

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!";
    }
}

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Lombok - java library

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join