View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.pattern.util;
15  
16  import ch.qos.logback.core.CoreConstants;
17  import ch.qos.logback.core.rolling.helper.FileNamePattern;
18  
19  /**
20   * This implementation is intended for use in {@link FileNamePattern}.
21   * 
22   * @author Ceki Gülcü
23   */
24  public class AlmostAsIsEscapeUtil extends RestrictedEscapeUtil {
25  
26      /**
27       * Do not perform any character escaping, except for '%', and ')'.
28       * 
29       * <p>
30       * Here is the rationale. First, filename patterns do not include escape
31       * combinations such as \r or \n. Moreover, characters which have special
32       * meaning in logback parsers, such as '{', or '}' cannot be part of file names
33       * (so me thinks). The left parenthesis character has special meaning only if it
34       * is preceded by %. Thus, the only characters that needs escaping are '%' and
35       * ')'.
36       * 
37       * <p>
38       * Note that this method assumes that it is called after the escape character
39       * has been consumed.
40       */
41      public void escape(String escapeChars, StringBuffer buf, char next, int pointer) {
42          super.escape("" + CoreConstants.PERCENT_CHAR + CoreConstants.RIGHT_PARENTHESIS_CHAR, buf, next, pointer);
43      }
44  }