Spring에 로그인

Dec 10 2020

스프링 부트 응용 프로그램이 있으며 시작 후 일반적으로 콘솔에 다음 출력이 표시됩니다.

 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.0)
1283 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path 

기타...

이 로그 출력이 필요합니다.

1283 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path 

slf4j를 사용하여 파일에 넣으십시오.

slf4j 설정을 가진 application.properties가 있습니다.

logging.level.root=INFO
logging.level.org.spring.upskill = INFO
logging.level.org.springframework.web = INFO
logging.file.name = app.log

그러나 파일에 대한 전체 출력을 얻지 못합니다. 내 GetMappings에 대한 응답 만

예를 들면

[2020-12-10 14:31:53.381] - 19960 INFO [main] --- org.apache.catalina.core.StandardService: Starting service [Tomcat]
[2020-12-10 14:31:53.385] - 19960 INFO [main] --- org.apache.catalina.core.StandardEngine: Starting Servlet engine: [Apache Tomcat/9.0.39]
[2020-12-10 14:31:53.432] - 19960 INFO [main] --- org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]: Initializing Spring embedded WebApplicationContext

어떻게해야합니까?

감사합니다!

답변

Saptarshi Dec 10 2020 at 16:14

속성에서 appender.rolling.policies.startup.type = OnStartupTriggeringPolicy를 사용하거나 Appenders-> RollingRandomAccessFile 내에 아래를 포함하도록 log4j2.xml을 업데이트 할 수 있다고 가정합니다.

    <Policies>
        <!-- Starts a new log on tomcat start -->
        <OnStartupTriggeringPolicy />
        <!-- Starts a new file when size reaches threshold -->
        <SizeBasedTriggeringPolicy size="100 MB" />
        <!-- causes a rollover once the date/time pattern no longer applies to 
            the active file
        <TimeBasedTriggeringPolicy /> -->
    </Policies>