import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.logging.Logger;
@RestController
public class SampleController {
private static final Logger logger = (Logger) LoggerFactory.getLogger(SampleController.class);
@GetMapping("/")
public String hello(HttpServletResponse response) throws IOException {
logger.info("403 Forbidden");
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied");
return null;
}
}
로깅 시 Slf4j에서 import를 해야하는데 LoggerFactory는 제대로 가져왔지만 Logger 객체가 java.util.logging에서 가져온 객체인것을 확인할 수 있다.
import java.util.logging.Logger;를 import org.slf4j.Logger;로 변경한다.
이후 Logger 선언문도 아래와 같이 수정한다.
private static final Logger logger = (Logger) LoggerFactory.getLogger(SampleController.class);
private static final Logger logger = LoggerFactory.getLogger(SampleController.class);