Composite Appender

The composite appender presents a single appender and appends to several appenders. It is very useful for referring to a list of appenders by a single name.

<configuration debug="true">

    <appender name="CONSOLE" class="">

    <appender name="FILE" class="">

    <appender name="CONSOLE_AND_FILE" class="com.tersesystems.logback.core.CompositeAppender">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>

    <root level="TRACE">
        <appender-ref ref="CONSOLE_AND_FILE"/>

You can leverage nesting to keep your filtering logic under control. For example, you may want to have several things happen when you hit an error in your logs. Appenders will always write when they receive an event, unless they are filtered.

Using nesting, you can declare the filter once, and have the child appenders "inherit" that filter:

<!-- Filter is on the appender chain -->
<appender name="ERROR-APPENDER" class="com.tersesystems.logback.CompositeAppender">
    <filter class="ch.qos.logback.classic.filter.LevelFilter">

    <appender class="ch.qos.logback.core.FileAppender">
            <pattern>%date - %message</pattern>

    <appender class="">
        <player class="">

<root level="TRACE">
    <appender-ref ref="ALL-APPENDER"/>
    <appender-ref ref="TRACE-APPENDER"/>
    <appender-ref ref="DEBUG-APPENDER"/>
    <appender-ref ref="INFO-APPENDER"/>
    <appender-ref ref="WARN-APPENDER"/>
    <appender-ref ref="ERROR-APPENDER"/>

This makes your appender logic much cleaner.

See Application Logging in Java: Appenders for more details.