0

I am using Logback logging library on Java. I prepared the logback.xml configuration, but it does not record to the target directory I specified. I share the configuration codes with you.

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
    <property name="USER_HOME" value="C:\LogSs" />
    <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</Pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">

        <file>${USER_HOME}/myApp.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${USER_HOME}/application_%d{yyyy-MM-dd}.%i.log</fileNamePattern>

            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>5MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!-- keep 30 days' worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
            <charset>UTF-8</charset>
            <pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="consoleAppender" />
        <appender-ref ref="FILE"/>
    </root>
    <root level="INFO">
        <appender-ref ref="consoleAppender" />
        <appender-ref ref="FILE"/>
    </root>
    <root level="ERROR">
        <appender-ref ref="consoleAppender" />
        <appender-ref ref="FILE"/>
    </root>
</configuration>
avcismail
  • 31
  • 6
  • That's because you're repeating level configurations for the root logger. Get rid of all apart from the DEBUG one. You can change the level of that as and when necessary – g00se Aug 23 '23 at 18:21
  • There was only debug before. But still my logs were not recorded. @g00se – avcismail Aug 24 '23 at 05:21
  • Works for me. Of course you didn't show its location relative to your classpath or how you're using it – g00se Aug 24 '23 at 08:44
  • so how can i do this? @g00se – avcismail Aug 24 '23 at 11:02
  • Well you should start by providing the missing info into your question. Also check that target directory is writable by the user running the process – g00se Aug 24 '23 at 11:56

0 Answers0