1 /*
2 * This file is part of AceLogger.
3 *
4 * AceLogger is free software: you can redistribute it and/or modify it under the terms of the GNU
5 * Lesser General Public License as published by the Free Software Foundation, either version 3 of
6 * the License, or (at your option) any later version.
7 *
8 * AceLogger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public License along with AceLogger.
13 * If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
14 */
15 package net.sourceforge.acelogger.appender;
16
17 import java.io.PrintStream;
18
19 import net.sourceforge.acelogger.LogEvent;
20 import net.sourceforge.acelogger.execution.manager.ExecutorManager;
21 import net.sourceforge.acelogger.formatter.Formatter;
22
23 /**
24 * An implementation of Appender abstracting common PrintStream writing.
25 *
26 * @author Zardi (https://sourceforge.net/users/daniel_zardi)
27 * @version 1.0.0
28 * @since 1.0.0
29 */
30 public class PrintStreamAppender extends BaseAppender {
31
32 /**
33 * The PrintStream where data will be written.
34 */
35 private PrintStream destination;
36
37 /**
38 * Constructs a new PrintStreamAppender with the supplied information.
39 *
40 * @param identifier
41 * A string that identifies this appender.
42 * @param destination
43 * The PrintStream where data will be written.
44 * @param formatter
45 * The Formatter used to format each log call.
46 * @param executor
47 * The ExecutorManager used to process the log calls.
48 * @since 1.0.0
49 */
50 public PrintStreamAppender(String identifier, PrintStream destination, Formatter formatter,
51 ExecutorManager executor) {
52 super(identifier, formatter, executor);
53 this.destination = destination;
54 }
55
56 /** {@inheritDoc} */
57 protected Runnable appendLogProcess(final LogEvent call) {
58 Runnable process = new Runnable() {
59 /**
60 * Prints the formated log call to the writer stream.
61 */
62 public void run() {
63 destination.print(formatLogCall(call));
64 destination.flush();
65 }
66 };
67 return process;
68 }
69
70 }