View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.access.pattern;
11  
12  import ch.qos.logback.access.spi.AccessEvent;
13  import ch.qos.logback.core.pattern.Converter;
14  import ch.qos.logback.core.pattern.ConverterUtil;
15  import ch.qos.logback.core.pattern.PostCompileProcessor;
16  
17  public class EnsureLineSeparation implements PostCompileProcessor<AccessEvent> {
18  
19    /**
20     * Add a line separator converter so that access event appears on a separate
21     * line.
22     */
23    public void process(Converter<AccessEvent> head) {
24      Converter<AccessEvent> tail = ConverterUtil.findTail(head);
25      Converter<AccessEvent> newLineConverter = new LineSeparatorConverter();
26      if (tail == null) {
27        head = newLineConverter;
28      } else {
29        if (!(tail instanceof LineSeparatorConverter)) {
30          tail.setNext(newLineConverter);
31        }
32      }
33    }
34  }