springlogbackspring-logback

How to specify default Logback configuration for any spring profile that is not already present in the config


Here is my simplified logback-spring.xml configuration:

<configuration>

    <!-- appender config -->

    <springProfile name=dev>
        <!-- dev specific config here -->
    </springProfile>

    <springProfile name=prod>
        <!-- prod specific config here -->
    </springProfile>

    <!-- other profiles -->

</configuration>

I would like to get some default logback configuration when I am running my app with some different profile. I couldn't find information about having some default configuration in logback-spring.xml.

Please, note that there are more than 2 profiles defined and I don't know the names of other temp profiles.

Thanks, Pavlo


Solution

  • Actually, found out that defining configuration outside of the profile tag does the job:

    <configuration>
    
        <!-- appenders and profiles -->
    
        <root level="level here">
            <appender-ref ref="name here"/>
        </root>
    
        <logger name="name here" level="level here"/>
        <!-- other loggers -->
    
    </configuration>
    

    In this case it will be taken as a base configuration. You can override appender-ref and loggers in profile specific block.