Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Spring Boot logback RollingFileAppender and have actuator logfile?

As I understand, /logfile actuator available only if logging.file= is in the application.properties file.

But for my logging I need RollingFileAppender file appender with SizeAndTimeBasedRollingPolicy.

Is it possible to configure RollingFileAppender in the application.properties?

If I configure RollingFileAppender in the logging-spring.xml there is an error:

java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - 'File' option has the same value "log/scratch6.log" as that given for appender [FILE] defined earlier.

Is it possible to have logfile via RollingFileAppender and have a /logfile actuator?

like image 572
Serge Nikitin Avatar asked Oct 19 '16 20:10

Serge Nikitin


1 Answers

I faced the same issue. Here is what i found

logging.file - actually creates a file. when you declare ${LOG_FILE} in your logback-spring.xml, it detects a collision. appender and file name with the same value.

I ended up doing this (appending with .log so that it differentiates the appender with the file)

application.properties: logging.file=/opt/fff/logs/file_debug

logback-spring.xml:

     <file>${LOG_FILE}.log</file>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>
            %d{yyyy-MM-dd HH:mm:ss} - %msg%n
        </Pattern>
    </encoder>

..

However it also creates another file /opt/fff/logs/file_debug in addition to /opt/fff/logs/file_debug.log

like image 141
Vijay Ram Avatar answered Oct 16 '22 23:10

Vijay Ram