## Chapter 4: Appenders

Authors: Ceki Gülcü, Sébastien Pennec

| Copyright © 2000-2006, QOS.ch This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License .

## What is an Appender

Logback delegates the task of writing a logging event to appenders. Appenders must imple-ment the `ch.qos.logback.core.Appender` interface. The salient methods of this interface are summarized below:

    package ch.qos.logback.core;

    import ch.qos.logback.core.spi.ContextAware;
    import ch.qos.logback.core.spi.FilterAttachable;
    import ch.qos.logback.core.spi.LifeCycle;

    public interface Appender extends LifeCycle, ContextAware, FilterAttachable {

      public String getName();
      void doAppend(Object event);
      public void setLayout(Layout layout);
      public Layout getLayout();
      public void setName(String name);

    }

Most of the methods in the Appender interface are made of setter and getter methods. A notable exception is the `doAppend()` method taking an Object instance as its only parameter. This method is perhaps the most important in the logback framework. It is responsible for outputting the logging events in a suitable format to the appropriate output device. Appenders are named entities. This ensures that they can be referenced by name, a quality confirmed to be especially significant in configuration scripts. An appender can contain multiple filters, thus the `Appender` interface extending the `FilterAttachable` interface. Filters are discussed in detail in a subsequent chapter.

Appenders are ultimately responsible for outputting logging events. However, they may delegate the actual formatting of the event to a `Layout` object. Each layout is associated with one and only one appender, referred to as the containing appender. Some appenders have a built-in or fixed event format, such that they do not require a layout. For example, the `SocketAppender` simply serialize logging events before transmitting them over the wire.

## AppenderBase

The `ch.qos.logback.core.AppenderSkeleton` class is an abstract class implementing the `Appender` interface. It provides basic functionality shared by all appenders, such as methods for getting or setting their name, their started status, their layout and their filters. It is the super-class of all appenders shipped with logback. Although an abstract class, AppenderBase actually implements the `doAppend()` method in the `Append` interface. Perhaps the clearest way to discuss AppenderBase class is by presenting a bit of its actual source code. `AppenderBase`'s complete source code is also available for viewing.

    public synchronized void doAppend(Object eventObject) {

      // prevent re-entry.
      if (guard) {
        return;
      }

      try {
        guard = true;

        if (!this.started) {
          if (statusRepeatCount++ < ALLOWED_REPEATS) {
            addStatus(new WarnStatus(
                "Attempted to append to non started appender [" + name + "].",this));
          }
          return;
        }

        if (getFilterChainDecision(eventObject) == FilterReply.DENY) {
          return;
        }

        // ok, we now invoke derived class' implementation of append
        this.append(eventObject);

      } finally {
        guard = false;
      }
    }

This implementation of the `doAppend()` method is synchronized. It follows that logging to the same appender from different threads is safe. While a thread, say T, is executing the `doAppend()` method, subsequent calls by other threads are queued until T leaves the `doAppend()` method, ensuring T's exclusive access to the appender.

The first thing the `doAppend()` method does is to set the `guard` variable to `true`. This ensures that the method will not call itself and create an infinite loop. Why could it call itself, you might ask? Well, just imagine that a logback component, called somewhere beyond the `append()` method, might want to log something. Its call could be directed to the very same appender that just called it, which would then call it again.

The first statement of the `doAppend()` method, once the `try` block is reached is to check whether the `started` field is true. If it is not, `doAppend()` will send a warning message and return. In other words, once stopped, it is impossible to write to a closed appender. `Appender` object implement the `LifeCycle` interface, which implies that they implement `start()`, `stop()` and `isStarted()` methods. After setting all the options of an appender, Joran, logback's configuration framework, calls this method to signal the appender to bind or activate its options. Indeed, depending on the appender, certain options cannot be activated because of interferences with other options, or appenders can even not start at all if some options are missing. For example, since file creation depends on truncation mode, `FileAppender` cannot act on the value of its `File` option until the value of the Append option is also known for certain. Sub-classes of `AppenderBase` are required to set the boolean variable `started` to false when their `stop()` method is invoked.

If a warning message is sent due to incorrect calls to the `doAppend()` method, logback's powerful `Status` error reporting system is used. In case several incorrect calls on `doAppend()` are issued, `AppenderBase` does not send an unlimited number of warnings. Once a certain limit is reached, the `AppenderBase` instance stops its warnings.

The next `if` statement checks the result of the attached `Filter` objects. Depending on the decision made by the filters in the filter chain, events can be denied or alternatively accepted. In the absence of a decision by the filter chain, events are accepted by default.

Lastly, the `doAppend()` method invoke the derived classes' implementation of the `append()` method, which does the actual work of appending the event to the appropriate device.

DO WE ADD A UML DIAGRAM?? YES!!

In appenders, the term option or property is reserved for named attributes that are dynamically inferred using JavaBeans introspection.

## Logback Core

### WriterAppender

`WriterAppender` appends events to a `java.io.Writer`. This class provides basic services that other appenders build upon. Users do not usually instantiate `WriterAppender` objects directly. Since `java.io.Writer` type cannot be mapped to a string, there is no way to specify the target `Writer` object in a configuration script. Simply put, you cannot configure a `WriterAppender` from a script. However, this does not mean that `WriterAppender` lacks configurable options. These options are described next.

Option Name | Type | Description
--- | --- | ---

Encoding

`String`

The encoding specifies the method of conversion between 16-bit Unicode characters into raw 8-bit bytes. This appender will use the local platform's default encoding unless you specify otherwise using the Encoding option. According to the `java.lang` package documentation, acceptable values are dependent on the VM implementation although all implementations are required to support at least the following encodings: US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE and UTF-16. By default, the Encoding option is null such that the platform's default encoding is used.

ImmediateFlush

`boolean`

If set to true, each write of a logging event is followed by a flush operation on the underlying `Writer` object. Conversely, if the option is set to false, each write will not be followed by a flush. In general, skipping the flush operation improves logging throughput by roughly 15%. The downside is that if the application exits abruptly, the unwritten characters buffered inside the `Writer` might be lost. This can be particularly troublesome as those unwritten characters may contain crucial information needed in identifying the reasons behind a crash. By default, the ImmediateFlush option is set to true.

In general, if you disable immediate flushing, then make sure to flush any output streams when your application exits. Otherwise, log messages will be lost as illustrated by the next example.

Example 4.1: Exiting an application without flushing (logback-examples/src/main/java/chapter4/ ExitWoes.java)

    package chapter4;

    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    import ch.qos.logback.classic.LoggerContext;
    import ch.qos.logback.core.WriterAppender;
    import ch.qos.logback.core.layout.DummyLayout;

    public class ExitWoes {

      public static void main(String[] args) throws Exception {
        LoggerContext lc = new LoggerContext();
        WriterAppender writerAppender = new WriterAppender();
        writerAppender.setContext(lc);
        writerAppender.setLayout(new DummyLayout());

        OutputStream os = new FileOutputStream("exitWoes1.log");
        writerAppender.setWriter(new OutputStreamWriter(os));
        writerAppender.setImmediateFlush(false);
        writerAppender.start();

        Logger logger = LoggerFactory.getLogger(ExitWoes1.class);

        logger.debug("Hello world.");
      }
    }

This example creates a `WriterAppender` that uses an `OutputStreamWriter` wrapping a `FileOutputStream` as its underlying `Writer` object, with immediate flushing disabled. It then proceeds to log a single debug message. According to `OutputStreamWriter` javadocs, each invocation of a `write()` method causes the encoding converter to be invoked on the given character(s). The resulting bytes are accumulated in a buffer before being written to the underlying output stream. As astonishing as this may seem, running `ExitWoes1` will not produce any output in the file exitWoes1.log because the Java VM does not flush output streams when it exits. Calling the `shutdown()` method of a XXXXXX ensures that all appenders in the hierarchy are closed and their buffers are flushed. For most applications this is as simple as including the following statement before exiting the application.

WHAT TO DO IN LB ???

The `WriterAppender` is the super class of four other appenders, namely `ConsoleAppender`, `FileAppender` which in turn is the super class of `RollingFileAppender`.

include UML?? Figure 4 2 illustrates the class diagram for WriterAppender and its subclasses

### ConsoleAppender

The `ConsoleAppender`, as the name indicates, appends on the console, or more precisely on System.out or System.err, the former being the default target. `ConsoleAppender` formats events with a layout specified by the user. Both System.out and System.err are `java.io.PrintStream` objects. Consequently, they are wrapped inside an `OutputStreamWriter` which buffers I/O operations but not character conversions.

Option Name | Type | Description
--- | --- | ---
Encoding | `String` | See `WriterAppender` options.
ImmediateFlush | `boolean` | See `WriterAppender` options.
Target | `String` | One of the String values System.out or System.err. The default target is System.out.

### FileAppender

The `FileAppender`, a subclass of `WriterAppender`, appends log events into a file. The file to write to is specified by the File option. If the file already exists, it is either appended to, or truncated depending on the value of the Append option. It uses a `FileOutputStream` which is wrapped by an `OutputStreamWriter`. Note that `OutputStreamWriter` buffers I/O operations but not character conversions. To optimize character conversions one can set the BufferedIO option to true which effectively wraps the `OutputStreamWriter` with a `BufferedWriter`. Options for `FileAppender` are summarized below.

Option Name | Type | Description
--- | --- | ---
Append | `boolean` | If true, events are appended at the end of an existing file. Otherwise, if Append is false, any existing file is truncated. The Append option is set to true by default.
Encoding | `String` | See `WriterAppender` options.

BufferedIO

`boolean`

The BufferedIO option is set to false by default. If set to true, the underlying `OutputStreamWriter` is wrapped by a `BufferedWriter` object. Setting BufferedIO to true automatically sets the ImmediateFlush option to false. The name BufferedIO is slightly misleading because buffered IO is already supported by `OutputStreamWriter`. Setting BufferedIO to true has the effect of buffering I/O as well as character to raw byte conversions, saving a few CPU cycles in the process.

BufferSize | `int` | Size of `BufferedWriter` buffer. The default value is 8192.

File

`int`

The name of the file to write to. If the file does not exist, it is created.
On the MS Windows platform users frequently forget to escape back slashes. For example, the value c:\temp\test.log is not likely to be interpreted properly as '\t' is an escape sequence interpreted as a single tab character (\u0009). Correct values can be specified as c:/temp/test.log or alternatively as c:\\temp\\test.log. The File option has no default value.

By default, `FileAppender` performs a flush operation for each event, ensuring that events are immediately written to disk. Setting the ImmediateFlush option to false can drastically reduce I/O activity by letting `OutputStreamWriter` buffer bytes before writing them on disk. For short messages, we have observed 2 or 3 fold increases in logging throughput, i.e. the number of logs output per unit of time. For longer messages, the throughput gains are somewhat less dramatic, and range between 1.4 and 2 fold. Enabling the BufferedIO option, that is buffering character to byte conversions, increases performance by an additional 10% to 40% compared to only disk I/O buffering (ImmediateFlush=false). Performance varies somewhat depending on the host machine as well as JDK version. Throughput measurements are based on the `chapter4.IO` application. Please refer to the file logback-examples/src/main/java/chapter4/IO.java for actual source code. Online viewing of this file is also available.

### RollingFileAppender

`RollingFileAppender` extends `FileAppender` by allowing rolling from a log file to another. For example, `RollingFileAppender` can log to a log.txt file and, once a certain condition is met, change its logging target to another file.

There are two important logback componenents that interact with `RollingFileAppender`. First, `RollingPolicy` implementation define the procedure that will be followed when the rollover happens. The second componenent is `TriggeringPolicy` implementations that are used to check wether the rollover must happen or not at a given time.

To be of any use, a `RollingFileAppender` must have both a `RollingPolicy` and a `TriggeringPolicy` set up. However, if its `RollingPolicy` also implements the `TriggeringPolicy` interface, then only the former needs to be set up.

Here are the available options for `RollingFileAppender`:

Option Name | Type | Description
--- | --- | ---
Append | `boolean` | See `FileAppender` options.
BufferedIO | `boolean` | See `FileAppender` options.
BufferSize | `int` | See `FileAppender` options.
Encoding | `int` | See `WriterAppender` options.
File | `int` | See `FileAppender` options.
ImmediateFlush | `int` | See `WriterAppender` options.
RollingPolicy | `RollingPolicy` | This option is the component that will dictate `RollingFileAppender`'s behaviour when the rollover occurs. See more information below.
TriggeringPolicy | `TriggeringPolicy` | This option is the component that will tell `RollingFileAppender` when to activate the rollover procedure. See more information below.

### Rolling policies

`RollingPolicy` implementations are responsible for the procedure of the rollover. They manage file renaming and sometimes deleting.

The `RollingPolicy` interface is rather simple:

    package ch.qos.logback.core.rolling;

    import ch.qos.logback.core.FileAppender;
    import ch.qos.logback.core.spi.LifeCycle;

    public interface RollingPolicy extends LifeCycle {

      public void rollover() throws RolloverFailure;
      public String getNewActiveFileName();
      public void setParent(FileAppender appender);
    }

The `rollover` method proceeds to the file change, renaming or deletion. The `getNewActiveFileName()` method is called to compute a new file name, with respect to the configuration elements that were injected in the `RollingPolicy`. Lastly, a `RollingPolicy` knows about its parent.

#### FixedWindowRollingPolicy

When rolling over, `FixedWindowRollingPolicy` renames files according to a fixed window algorithm as described below.

The Fileproperty, which is configured in the `FileAppender` element, is required. It represents the name of the file where current logging output will be written. The FileNamePattern option represents the file name pattern for the archived (rolled over) log files. The FileNamePattern option, which is also required, must include an integer token, that is the string %i somewhere within the pattern.

Here are the available options for `FixedWindowRollingPolicy`

Option Name | Type | Description
--- | --- | ---

FileNamePattern

`String`

This option represents the pattern that will be followed by the `FixedWindowRollingPolicy` when renaming the log files. If must contain the string %i, which will indicate the position where to insert the file's index.

For example, using MyLogFile%i.log, associated with minimum and maximum values of 1 and 3 will produce files named MyLogFile1.log, MyLogFile2.log and MyLogFile3.log.

File compression is also specified in the FileNamePattern option. MyLogFile%i.log.zip will indicate to the `FixedWindowRollingPolicy` that the archived file must be compressed using the zip format. The gz format is also supported.

MaxIndex | `int` | This option represents the maximum border of the window algorithm.
MinIndex | `int` | This option represents the minimum border of the window algorithm.

Given that this rollover algorithm requires as many file renaming operations as the window size, large window sizes are discouraged. The current implementation will automatically reduce the window size to 12 when larger values are specified by the user.

Here is an example of file handling by `FixedWindowRollingPolicy`. We suppose that the MinIndex is set to 1 and MaxIndex is set to 3. The FileNamePattern option is set to foo%i.log, and the `FileAppender`'s FileNamePattern option is set to foo.log.

Steps | Active file name | Archived file names | Description
--- | --- | --- | ---
0 | foo.log | - | No rollover has happened yet, logback logs into the initial file.
1 | foo.log | foo1.log | First rollover. foo.log is renamed into foo1.log and a new foo.log file is created and used for the output.
2 | foo.log | foo2.log, foo1.log | Second rollover. foo.log is renamed into foo1.log and the old foo1.log is renamed into foo2.log. Again, a new foo.log file is created and used for the output.
3 | foo.log | foo3.log, foo2.log, foo1.log | Third rollover. foo.log is renamed into foo1.log and the old foo1.log is renamed into foo2.log. As well, the old foo2.log is renamed into foo3.log. A new foo.log file is created and used for the output.
4 | foo.log | foo3.log, foo2.log, foo1.log | At the fourth rollover, the old foo3.log file is deleted. The files are all renamed with an increment to their index, and a new foo.log file is created and used for the output. From this moment on, there will always be 4 log files available, each being present for the time of 3 rollovers and being deleted afterwards.

Here is a sample configuration to use `RollingFileAppender` and `FixedWindowRollingPolicy`.

    <configuration>
      <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>testFile.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
          <FileNamePattern>testFile.%i.log.zip</FileNamePattern>
          <MinIndex>1</MinIndex>
          <MaxIndex>3</MaxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
          <MaxFileSize>5MB</MaxFileSize>
        </triggeringPolicy>
        <layout class="ch.qos.logback.classic.PatternLayout">
          <Pattern>%-4relative [%thread] %-5level %class - %msg%n</Pattern>
        </layout>
      </appender>

      <root>
        <level value="debug" />
        <appender-ref ref="FILE" />
      </root>
    </configuration>

#### TimeBasedRollingPolicy

`TimeBasedRollingPolicy` is both easy to configure and quite powerful. It allows the rollover to be made based on time conditions. It is possible to specify that the rollover must occur each day, or month, for example.

`TimeBasedRollingPolicy`'s only option is the FileNamePattern.

In order to use `TimeBasedRollingPolicy`, the FileNamePattern option must be set. It basically specifies the name of the rolled log files. The value FileNamePattern should consist of the name of the file, plus a suitably placed %d conversion specifier. The %d conversion specifier may contain a date and time pattern as specified by the `java.text.SimpleDateFormat` class. If the date and time pattern is omitted, then the default pattern of yyyy-MM-dd is assumed. The following examples should clarify the point.

FileNamePattern | Roll-over schedule | Example
--- | --- | ---

/wombat/folder/foo.%d

Daily rollover (at midnight). Due to the omission of the optional time and date pattern for the %d token specifier, the default pattern of yyyy-MM-dd is assumed, which corresponds to daily rollover.

During November 23rd, 2006, logging output will go to the file /wombat/foo.2006-11-23. At midnight and for the rest of the 24th, logging output will be directed to /wombat/foo.2006-11-24.

/wombat/foo.%d{yyyy-MM}.log | Rollover at the beginning of each month. | During the month of October 2006, logging output will go to /wombat/foo.2006-10.log. After midnight of October 31st and for the rest of November, logging output will be directed to /wombat/foo.2006-11.log.
/wombat/foo.%d{yyyy-ww}.log | Rollover at the first day of each week. Note that the first day of the week depends on the locale. | During the 23rd week of 2006, the file /wombat/foo.2006-23.log will contain the actual logging output. Logging for the 24th week of 2006 will be output to /wombat/foo.2006-24.log until it is rolled over at the beginning of the next week.
/wombat/foo.%d{yyyy-MM-dd-a}.log | Rollover at midnight and midday of each day. | During the first 12 hours of November 3rd, 2006, the logging will be output to /wombat/foo.2006-11-03-AM.log. After noon, and until midnight, the logging will be output to /wombat/foo.2006-11-03-PM.log.
/wombat/foo.%d{yyyy-MM-dd_HH}.log | Rollover at the top of each hour. | Between 11.00,001 and 11.59,999, on November 3rd, 2006, the logging will be output to /wombat/foo.2006-11-03_11.log. After that, and until 12.59,999, the logging will be output to /wombat/foo.2006-11-03_12.log.
/wombat/foo.%d{yyyy-MM-dd_HH-mm}.log | Rollover at the beggining of every minute. | Between 11.32,001 and 11.32,999, on November 3rd, 2006, the logging will be output to /wombat/foo.2006-11-03_11-32.log. After that, and until 12.33,999, the logging will be output to /wombat/foo.2006-11_12-33.log.

Any characters in the pattern outside the ranges ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like '.', ' ', '#' and '@' will appear in the resulting time text even when they are not enclosed within single quotes. Nevertheless, we would recommend against using the colon ":" character anywhere within the FileNamePattern option. The text before the colon is interpreted as the protocol specification of a URL, which is most probably not what you intend. The slash "/" character, a common date field separator, must also be avoided. It is taken as a file separator causing the rollover operation to fail because the target file cannot be created. Although less common, the backslash character "\" is equally troublesome.

Just like `FixedWindowRollingPolicy`, `TimeBasedRollingPolicy` supports automatic file compression. This feature is enabled if the value of the FileNamePattern option ends with .gz or .zip.

FileNamePattern | Rollover schedule | Example
--- | --- | ---

/wombat/foo.%d.gz

Daily rollover (at midnight) with automatic GZIP compression of the arcived files.

During November 23rd, 2004, logging output will go to the file /wombat/foo.2004-11-23. However, at midnight that file will be compressed to become /wombat/foo.2004-11-23.gz. For the 24th of November, logging output will be directed to /wombat/folder/foo.2004-11-24 until its rolled over at the beginning of the next day.

As we have seen, the FileNamePattern serves two purposes. First, by studying the pattern, logback computes the requested rollover periodicity. Second, it uses the pattern to custom each rolled files. It is entirely possible for two different file name patterns to specify the same periodicity. The date patterns yyyy-MM and yyyy@MM both specify monthly rollover periodicity, although the rolled files will carry different customizations.

Given the use of the FileNamePattern, we see that the `TimeBasedRollingPolicy` is responsible for the rollover as well as for the triggering of said rollover. Therefore, `TimeBasedTriggeringPolicy` implements `RollingPolicy` as well as `TriggeringPolicy` interfaces. A `RollingFileAppender` that uses `TimeBasedRollingPolicy` can be started and used correctly even if its configuration does not contain any reference to a `TriggeringPolicy`.

With `TimeBasedRollingPolicy`, it is possible to decouple the location of the active log file and the archived log files

The File option defines the log file for the current period whereas archived files are those files which have been rolled over in previous periods.

By setting the File option you can decouple the location of the active log file and the location of the archived log files. The actual logging will be done in the file specified by the File option. This way, the active file name will never change. By not setting the File option, logback uses the FileNamePattern to name the active file, whose name will change each time a rollover occurs.

For various efficiency reasons, rollovers are not time-driven but depend on the arrival of logging events. For example, on 8th of March 2002, assuming the FileNamePattern is set to yyyy-MM-dd (daily rollover), the arrival of the first event after midnight will trigger rollover. If there are no logging events during, say 23 minutes and 47 seconds after midnight, then rollover will occur at 00:23'47 AM on March 9th and not at 0:00 AM. Thus, depending on the arrival rate of events, rollovers might be triggered with some latency. However, regardless of the delay, the rollover algorithm is known to be correct, in the sense that all logging events generated during a certain period will be output in the correct file delimiting that period.

Here is a sample configuration of a `RollingFileAppender` which uses a `TimeBasedRollingPolicy`

    <configuration>
      <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>logFile.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
          <FileNamePattern>logFile.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>

        <layout class="ch.qos.logback.classic.PatternLayout">
          <Pattern>%-4relative [%thread] %-5level %class - %msg%n</Pattern>
        </layout>
      </appender>

      <root>
        <level value="debug" />
        <appender-ref ref="FILE" />
      </root>
    </configuration>

### Triggering policies

`TriggeringPolicy` implementations are responsible for instructing the `RollingFileAppender` to proceed to the rollover.

The `TriggeringPolicy` interface is pretty simple.

    package ch.qos.logback.core.rolling;

    import java.io.File;
    import ch.qos.logback.core.spi.LifeCycle;

    public interface TriggeringPolicy extends LifeCycle {

      public boolean isTriggeringEvent(final File file, final Object event);
    }

The `isTriggeringEvent()` method takes the active file, and the currently processed logging event. It's implementation decied, based on these parameters, whether the rollover must occur or not, by returning a boolean value.

#### SizeBasedTriggeringPolicy

`SizeBasedTriggeringPolicy` looks at size of the file being currently written to. If it grows bigger than the specified size, the `FileAppender` using the `SizeBasedTriggeringPolicy` will proceed to the rollover of the current file and log to a new one.

This `TriggeringPolicy` only accepts one parameter, that is the MaxFileSize option. This option's default value is 10 MB.

The MaxFileSize option can be specified in a simple and easy way, by specifying the unit that should be used. One can enter any numeric value, with three possible units, namely KB, MB and GB. Consequently, values like 5MB, 500KB or 2GB are all valid.

Althought values expressed in GB are possible, we do not recommand setting the MaxFileSize option to a value bigger than XXX GB.

Here is a sample configuration with a `RollingFileAppender` using a `SizeBasedTriggeringPolicy`.

    <configuration>
      <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>testFile.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
          <FileNamePattern>testFile.%i.log.zip</FileNamePattern>
          <MinIndex>1</MinIndex>
          <MaxIndex>3</MaxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
          <MaxFileSize>5MB</MaxFileSize>
        </triggeringPolicy>
        <layout class="ch.qos.logback.classic.PatternLayout">
          <Pattern>%-4relative [%thread] %-5level %class - %msg%n</Pattern>
        </layout>
      </appender>

      <root>
        <level value="debug" />
        <appender-ref ref="FILE" />
      </root>
    </configuration>

`TriggeringPolicy` implementations do not only serve with `RollingFileAppender` objects. They can also be used to tell `SMTPAppender`, which will be covered soon, when to send an email containing the last logging events.

## Logback Classic

## Logback Access