Iniciar sesión Spring

Dec 10 2020

Tengo una aplicación de arranque de primavera, y después de que se inicia, generalmente vemos el siguiente resultado en la consola

 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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 

etc ...

Necesito obtener esta salida de registro:

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

y ponerlo en el archivo usando slf4j

Tengo una application.properties con la configuración de slf4j

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

Pero no obtengo una salida completa del archivo. Solo respuestas a mis GetMappings

Por ejemplo

[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

¿Cómo hago esto?

¡Gracias!

Respuestas

Saptarshi Dec 10 2020 at 16:14

Supongo que puede usar appender.rolling.policies.startup.type = OnStartupTriggeringPolicy en propiedades o actualizar log4j2.xml para incluir lo siguiente dentro de Appenders -> RollingRandomAccessFile

    <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>