0
votes

I need to disable application logs in console for my web application. I have below logback-spring.xml to force spring to use file appender instead of console appender. However, the problem now is my application log is written with all the logs from all the packages, even from those that are not specified in the logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>

<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />


<springProfile name="local,dev,qa,prodsup,perftest">
    <logger name="org.application.folder" level="debug" />
    <logger name="org.springframework.*" level="debug" />
    <root level="debug">
        <appender-ref ref="FILE" />
    </root>
</springProfile>



<springProfile name="prod">
    <logger name="org.application.folder" level="error" />
    <logger name="org.springframework.core " level="error" /> 
    <logger name="org.springframework.beans" level="error" />
    <logger name="org.springframework.context" level="error" />
    <logger name="org.springframework.transaction" level="error" />
    <logger name="org.springframework.web" level="error" />
    <logger name="org.springframework.test" level="error" />
    <logger name="org.springframework.boot.context" level="error"/>

</springProfile>

I am using spring boot 1.5.2. I specified the log file location in application.properties using logging.file key. I am currently using Websphere but I face the same problem with embedded tomcat as well.

Thank you.

1
What's the content of the config files you're including (defaults and file-appender)? - Xtreme Biker
They are the base files that spring-boot provides. Git link for defaults.xml(github.com/spring-projects/spring-boot/blob/master/spring-boot/…). Git link for file-appender.xml (github.com/spring-projects/spring-boot/blob/master/spring-boot/…) - Sachin Kumar
Perhaps Spring Boot isn't reading your logback-spring.xml at all? Maybe Logback is initialising itself from a different file, perhaps it found logback.xml or logback-test.xml on the classpath before your logback-spring.xml. Or maybe it couldn't find any configuration files on the classpath so it is running with the default configuration. If you run your application with -Dlogback.debug=true then Logback will write log messages (to console) whcih tell you where it configured itself from. - glytching
I added -Dlogback.debug=true and the configuration looks correct. I found the problem though looking at the logs. - Sachin Kumar

1 Answers

0
votes

I think I missed on the basics of logging. I have configured the root logger to use file-appender which is the reason why all the logs from all the packages were present in my configured file.(LOG_FILE env property value or logging.file in application properties.) I changed the logback-spring.xml as below and it works as I expected.

<?xml version="1.0" encoding="UTF-8"?>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />


<springProfile name="local,dev,qa,prodsup,perftest">
    <logger name="org.application.folder" level="debug" >
        <appender-ref ref="FILE" />
     </logger>
    <logger name="org.springframework" level="debug" >
         <appender-ref ref="FILE" />
    </logger>

</springProfile>