728x90
application.yml
- 로그 파일이 생성될 위치를 설정한다
server.tomcat.basedir:/var/log/
AccessLoggingConfig
- 로깅 파일의 내용과 제목 등을 설정한다
@Configuration
public class AdminAccessLogConfig implements WebServerFactoryCustomizer {
@Override
public void customize(WebServerFactory factory) {
final TomcatServletWebServerFactory containerFactory = (TomcatServletWebServerFactory) factory;
final AccessLogValve accessLogValve = new AccessLogValve();
accessLogValve.setPattern("%{yyyy-MM-dd HH:mm:ss}t\t%s\t%r\t%{User-Agent}i\t%{Referer}i\t%a\t%b");
accessLogValve.setDirectory(".");
accessLogValve.setSuffix(".log");
accessLogValve.setCondition("ignoreLogging");
containerFactory.addContextValves(accessLogValve);
}
}
LoggingFilter
- Http 요청을 제외한 static 파일 요청에 대한 로깅을 필터링한다
@Component
public class LoggingFilter implements Filter {
private final static String EXCLUDE_MATCH_REGEX = "/(health|.+\\.(css|js))";
@Override
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
final String uri = ((HttpServletRequest) request).getRequestURI();
if (uri.matches(EXCLUDE_MATCH_REGEX)) {
request.setAttribute("ignoreLogging", true);
}
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void destroy() {
}
}
출처
728x90