1 /**
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2011, 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.encoder;
15
16 import java.io.IOException;
17 import java.io.OutputStream;
18
19 import ch.qos.logback.core.spi.ContextAware;
20 import ch.qos.logback.core.spi.LifeCycle;
21
22 /**
23 * Encoders are responsible for transform an incoming event into a byte array
24 * *and* writing out the byte array onto the appropriate {@link OutputStream}.
25 * Thus, encoders have total control of what and when gets written to the
26 * {@link OutputStream} maintained by the owning appender.
27 *
28 *
29 * @author Ceki Gülcü
30 * @author Joen Huxhorn
31 * @author Maarten Bosteels
32 *
33 * @param <E>
34 * event type
35 * @since 0.9.19
36 */
37 public interface Encoder<E> extends ContextAware, LifeCycle {
38
39 /**
40 * This method is called when the owning appender starts or whenever output
41 * needs to be directed to a new OutputStream, for instance as a result of a
42 * rollover. Implementing encoders should at the very least remember the
43 * OutputStream passed as argument and use it in future operations.
44 *
45 * @param os
46 * @throws IOException
47 */
48 void init(OutputStream os) throws IOException;
49
50 /**
51 * Encode and write an event to the appropriate {@link OutputStream}.
52 * Implementations are free to differ writing out of the encoded event and
53 * instead write in batches.
54 *
55 * @param event
56 * @throws IOException
57 */
58 void doEncode(E event) throws IOException;
59
60 /**
61 * This method is called prior to the closing of the underling
62 * {@link OutputStream}. Implementations MUST not close the underlying
63 * {@link OutputStream} which is the responsibility of the owning appender.
64 *
65 * @throws IOException
66 */
67 void close() throws IOException;
68 }