1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org |
2 | * |
3 | * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. |
4 | * |
5 | * "Hilbert II" is free software; you can redistribute |
6 | * it and/or modify it under the terms of the GNU General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | */ |
15 | |
16 | package org.qedeq.kernel.bo.log; |
17 | |
18 | import java.io.PrintStream; |
19 | |
20 | import org.qedeq.base.utility.DateUtility; |
21 | |
22 | /** |
23 | * Listener that writes events to a stream. |
24 | * |
25 | * @author Michael Meyling |
26 | */ |
27 | public final class ModuleLogListenerImpl implements ModuleLogListener { |
28 | |
29 | /** Stream for output. */ |
30 | private PrintStream out = System.out; |
31 | |
32 | /** For this module we are logging. */ |
33 | private final String moduleUrl; |
34 | |
35 | /** |
36 | * Constructor. |
37 | * |
38 | * @param moduleUrl We log for this module. |
39 | */ |
40 | public ModuleLogListenerImpl(final String moduleUrl) { |
41 | this(moduleUrl, System.out); |
42 | } |
43 | |
44 | /** |
45 | * Constructor. |
46 | * |
47 | * @param moduleUrl We log for this module. |
48 | * @param stream Print to this stream. |
49 | */ |
50 | public ModuleLogListenerImpl(final String moduleUrl, final PrintStream stream) { |
51 | this.moduleUrl = moduleUrl; |
52 | this.out = stream; |
53 | } |
54 | |
55 | /** |
56 | * Set output stream. |
57 | * |
58 | * @param stream Output stream. |
59 | */ |
60 | public final void setPrintStream(final PrintStream stream) { |
61 | this.out = stream; |
62 | } |
63 | |
64 | public final void logMessageState(final String text) { |
65 | out.println(moduleUrl); |
66 | out.println(DateUtility.getTimestamp() + " state: " + text); |
67 | } |
68 | |
69 | } |