0

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 ?

jozinho22
  • 459
  • 2
  • 7
  • 24
  • 1
    That's not how [repositories work](https://stackoverflow.com/q/38509882/2541560) and due to generics erasure you can't make them work like that. Follow the documentation and don't try to get clever unless you know how the mechanisms work and can be extended. – Kayaman Dec 01 '20 at 00:08

1 Answers1

0

OK,

I had to put the logback.xml in the main path of the project.

jozinho22
  • 459
  • 2
  • 7
  • 24