Logback is not writing specific log file Solution


Logback is not writing specific log file Solution
Logback Configuration:
<property name="DEV_HOME" value="/root/apps/logs" />
<appender name="FILE-AUDIT"     class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${DEV_HOME}/myapp.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- rollover daily -->
        <fileNamePattern>${DEV_HOME}/archived/myapp.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <!-- or whenever the file size reaches the max -->
            <maxFileSize>${rolling.file.max.size}</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
        <maxHistory>${rolling.file.max.history}</maxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>${rolling.file.encoder.pattern}</pattern>
    </encoder>
</appender>

Issue is related to conflict between log4j and Logback, when we migrate from old log4j to Logback. You need to exclude lo4j dependencies from existing dependencies by running this command:

$ mvn dependency:tree


= >Add these jars only for logging using SLF4j and Logback

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${version.slf4j}</version>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${version.logback}</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
        <version>${version.slf4j}</version>
        <scope>runtime</scope>
    </dependency>

Posted detail issue on StackOverflow:

http://stackoverflow.com/questions/35813027/logback-is-not-writing-specific-log-file-on-the-linux-serverĀ