0
votes

I am using LogBack for logging and i currently have it setup like this

<configuration>
    <property resource="application.properties"/>
    <timestamp key="byDay" datePattern="yyyyMMdd"/>
    <if condition='property("spring.profiles.active").contains("prod")'>
        <then>
            <appender name="FILE" class="ch.qos.logback.core.FileAppender">
                <file>${logging.path}/myFileExt-${byDay}.log</file>
                <append>true</append>
                <encoder>
                    <pattern>%d{HH:mm:ss.SSS - yyyy.MM.dd} - [%thread] %-5level %C - %msg%n</pattern>
                </encoder>
            </appender>
            <logger name="com.mywebsite.myapp.services" level="INFO">
                <appender-ref ref="FILE"/>
            </logger>
            <logger name="com.mywebsite.myapp.utils" level="ERROR">
                <appender-ref ref="FILE"/>
            </logger>
            <root>
                <appender-ref ref="FILE"/>
            </root>
        </then>
        <else>
            <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
                <encoder>
                    <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} at line:%L - %msg%n</pattern>
                </encoder>
            </appender>
            <root level="debug">
                <appender-ref ref="STDOUT"/>
            </root>
        </else>
    </if>

</configuration>

I want to have it so services package is logged at level INFO or higher and utils package is logged at level ERROR or higher. But all i get are the ERROR logs for both of those packages. There must be something i am missing.

I have read this documentation https://logback.qos.ch/manual/configuration.html but it doesn't work as expected.

1

1 Answers

0
votes

I was using wrong class when getting the logger.

Logger logger = LogManager.getLogger(classInUtils.class)

should have been

Logger logger = LogManager.getLogger(classInServices.class)