I generate a spring boot project, and I want to log in an external file.
I choose to use Logback implementation, and here is my logback.xml
file :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_PATH" value="./logs" />
<appender name="CONSOLE"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)]
%yellow(%C{1.}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="SAVE_TO_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/spring-boot-logger.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
</appender>
<!-- LOG everything at INFO level -->
<root level="INFO">
<appender-ref ref="SAVE_TO_FILE" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>
I use to log with the classic line of code to log :
LoggerFactory.getLogger(CustomLogger.class);
I know that there is an implementation by default, and suspect my logback.xml
(which is as the root of the project) is not taking in consideration.
Is there somewhere I have to specify the name of the file, or import it in my application as a resource ?
OK,
I had to put the logback.xml
in the main
path of the project.