내장된 Tomcat의 액세스 로그를 stdout으로 전송하도록 Spring Boot에 어떻게 지시합니까?
스탠드아론의 Spring Boot 웹 애플리케이션(실행 가능 jar)에서는 임베디드 Tomcat 인스턴스의 HTTP 액세스 로그를 stdout으로 전송하도록 Spring Boot에 어떻게 전달합니까?
업데이트 2019.02.11:
이러한 잉크는 설정할 속성을 매핑하는 데 유용합니다.application.properties
:
@acohen의 답변은 약간 정확합니다.빈 큰따옴표를 지정하면 작동하지 않습니다.종속성을 추가하거나 코드를 수정하는 데 방해가 되고 싶지 않은 사람들에게 중요하기 때문에 그의 답변을 연장해 보겠습니다.
config/application.properties
# here we say that we want to enable accesslog
server.tomcat.accesslog.enabled=true
# it is important to understand what the options means:
# 'directory/prefix + suffix + file-date-format' will be
# the file that tomcat will try to open.
# /dev/stdout is standard output, so we want tomcat
# to write to that fd. Then, we need to play with
# directory, prefix, suffix and file-date-format to match our desired path.
server.tomcat.accesslog.directory=/dev
server.tomcat.accesslog.prefix=stdout
server.tomcat.accesslog.buffered=false
# Don't use empty double quotes, see below
server.tomcat.accesslog.suffix=
server.tomcat.accesslog.file-date-format=
메모들
- 설정했을 경우
file-date-format
그리고.suffix
큰따옴표로 묶으면 다음 오류가 발생합니다.
java.io.FileNotFoundException: /dev/stdout"""" (Permission denied)
- 컨피규레이션파일에 포함하지 않으면 기본값과 다음 오류가 사용됩니다.
java.io.FileNotFoundException: /dev/stdout.2019-02-07.log (Permission denied)
- 비워두면 효과가 있을 거예요.
Logback을 사용하는 경우 로그백액세스를 사용할 수 있습니다.
종속성 추가ch.qos.logback:logback-access
TeeFilter를 추가하기 위한 옵션 Javaconfig(요구 및 응답 로깅):
@Bean(name = "TeeFilter")
public Filter teeFilter() {
return new ch.qos.logback.access.servlet.TeeFilter();
}
내장 Tomcat용 Javaconfig:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
// put logback-access.xml in src/main/resources/conf
tomcat.addContextValves(new LogbackValve());
return tomcat;
}
의 내용logback-access.xml
(저장처src/main/resources/conf
)
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>combined</Pattern>
<Pattern>%fullRequest%n%n%fullResponse</Pattern>
</encoder>
</appender>
<appender-ref ref="STDOUT" />
</configuration>
Spring Boot 2.x에서는 이것으로 끝입니다.
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.directory=/dev
server.tomcat.accesslog.prefix=stdout
server.tomcat.accesslog.buffered=false
server.tomcat.accesslog.suffix=""
server.tomcat.accesslog.file-date-format=""
다음은 Spring Boot 2.0.0+에 대한 JohanB의 훌륭한 답변에 대한 후속 조치입니다.
Spring Boot 2.0.0에서는EmbeddedServletContainerFactory
로 대체되었다.TomcatServletWebServerFactory
JohanB의 답변의 다른 모든 측면은 여전히 올바르게 작동합니다.공장 콩의 작성은 변경만 하면 됩니다.
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
// put logback-access.xml in src/main/resources/conf
tomcat.addContextValves(new LogbackValve());
return tomcat;
}
JohanB의 솔루션은 기능하지만 코드를 기술하고 싶지 않은 경우 누군가가 더 잘 처리하여 서버 액세스 로그를 Spring Boot Starter에 랩했습니다.Tomcat, Jetty 및 Undertow에 대해 설명합니다.
종속성을 추가합니다.
<dependency>
<groupId>net.rakugakibox.spring.boot</groupId>
<artifactId>logback-access-spring-boot-starter</artifactId>
<version>2.7.1</version>
</dependency>
classpath root에 logback-access.xml 파일이 있습니다.
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>common</pattern>
</encoder>
</appender>
<appender-ref ref="CONSOLE" />
</configuration>
액세스 로그가 stdout 에 인쇄됩니다.
127.0.0.1 - - [08/févr./2019:11:23:30 +0100] "GET /password HTTP/1.1" 200 32
이 시점에서 디버깅을 위해 완전한 HTTP 요구와 응답을 인쇄하려면 Bean을 직접 작성해야 합니다.
언급URL : https://stackoverflow.com/questions/36780680/how-do-you-tell-spring-boot-to-send-the-embedded-tomcats-access-logs-to-stdout
'sourcetip' 카테고리의 다른 글
대응: 스테이트리스 기능 컴포넌트의 PropType (0) | 2023.03.04 |
---|---|
OracleCommand SQL 매개 변수 바인딩 (0) | 2023.03.04 |
PL/SQL 예외 처리: 아무것도 하지 않음(예외 무시) (0) | 2023.03.04 |
AngularJS의 동일한 요소에 두 개의 지시어를 내포하는 방법은 무엇입니까? (0) | 2023.03.04 |
Jasmine을 사용한 각도 단위 테스트: spyOn 제거 또는 수정 방법 (0) | 2023.02.27 |