Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actuator /logfile endpoint no longer works with external logback configuration

I needed my logs to be rolling, so I have created a "logback-spring.xml" file and placed it src/main/resources. Works flawlessly.

The issue is that the actuator endpoint "/logfile" no longer works as I have removed the logging configuration from the "applications.yml" file. According to documentation, either "logging.path" or "logging.file" needs to be set in order to make the "/logfile" endpoint work. This however seem to conflict with my new 'xml configuration.

Here is my logback-spring.xml configuration for good measure:

<configuration debug="true" scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<property name="LOG_PATH" value="logs"/>
<property name="LOG_ARCHIVE" value="${LOG_PATH}/archive"/>

<appender name="RollingFile-Appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_FILE}</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_ARCHIVE}/bookingflow-%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>30</maxHistory>
        <totalSizeCap>1GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
        <pattern>%d %-5level [%thread] %logger : %msg%n</pattern>
    </encoder>
</appender>
<appender name="Async-Appender" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="RollingFile-Appender"/>
</appender>

<logger name="com.novasol.bookingflow.api" level="debug">
    <appender-ref ref="Async-Appender"/>
</logger>
<springProfile name="production">
    <logger name="com.novasol.bookingflow.api" level="error">
        <appender-ref ref="Async-Appender"/>
    </logger>
</springProfile>
</configuration>    

Any pointers appreciated.

Kind regards Lars

like image 798
Lars Rosenqvist Avatar asked Jul 06 '16 11:07

Lars Rosenqvist


1 Answers

Solved it in the following manner:

In application.yml

logging:
   config:
      classpath: "logback-spring.xml"
   file: logs/bookingflow.log

The "logback-spring.xml":

<configuration debug="true" scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<property name="LOG_ARCHIVE" value="${LOG_PATH}/archive"/>

<appender name="RollingFile-Appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_PATH}/${LOG_FILE}</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_ARCHIVE}/bookingflow-%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>30</maxHistory>
        <totalSizeCap>1GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
        <pattern>%d %-5level [%thread] %logger : %msg%n</pattern>
    </encoder>
</appender>
<appender name="Async-Appender" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="RollingFile-Appender"/>
</appender>

<logger name="com.novasol.bookingflow.api" level="debug">
    <appender-ref ref="Async-Appender"/>
</logger>
<springProfile name="production">
    <logger name="com.novasol.bookingflow.api" level="error">
        <appender-ref ref="Async-Appender"/>
    </logger>
</springProfile>

Finally found the solution:

The following needs to be specified

endpoints:
  logfile:
    external-file: logs/custom.log
like image 168
Lars Rosenqvist Avatar answered Oct 16 '22 00:10

Lars Rosenqvist