1 /*
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2026, 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 v2.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;
15
16 /**
17 * A minimal converter which sets up the general interface for derived classes.
18 * It also implements the functionality to chain converters in a linked list.
19 *
20 * @param <E> The type of the event object
21 * @author ceki
22 */
23 abstract public class Converter<E> {
24
25 Converter<E> next;
26
27 /**
28 * The convert method is responsible for extracting data from the event and
29 * storing it for later use by the write method.
30 *
31 * @param event the event to convert
32 */
33 public abstract String convert(E event);
34
35 /**
36 * In its simplest incarnation, a convert simply appends the data extracted from
37 * the event to the buffer passed as parameter.
38 *
39 * @param buf The input buffer where data is appended
40 * @param event The event from where data is extracted
41 */
42 public void write(StringBuilder buf, E event) {
43 buf.append(convert(event));
44 }
45
46 public final void setNext(Converter<E> next) {
47 if (this.next != null) {
48 throw new IllegalStateException("Next converter has been already set");
49 }
50 this.next = next;
51 }
52
53 public final Converter<E> getNext() {
54 return next;
55 }
56 }