1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.caleigo.toolkit.log;
20
21 import java.io.*;
22
23 /*** The StreamLogSubscriber provides logging to OutputStreams and Writers.
24 * Subsequently it can used for loggings to both the console and files.
25 *
26 * @author Dennis Zikovic
27 * @version 1.00
28 *
29 *//*
30 *
31 * WHEN WHO WHY & WHAT
32 * ------------------------------------------------------------------------------
33 * den 1 augusti 2001 Dennis Zikovic Creation
34 */
35 public class StreamLogReceiver extends AbstractLogReceiver
36 {
37
38 private PrintWriter mOutput;
39
40
41
42 /*** Default constructor for DefaultLogSubscriber.
43 */
44 public StreamLogReceiver()
45 {
46 this(System.out);
47 }
48
49 public StreamLogReceiver(OutputStream output)
50 {
51 this(new OutputStreamWriter(output));
52 }
53
54 public StreamLogReceiver(Writer output)
55 {
56 if(output instanceof PrintWriter)
57 mOutput = (PrintWriter)output;
58 else
59 mOutput = new PrintWriter(output);
60 }
61
62 public StreamLogReceiver(String fileName) throws IOException
63 {
64 this(new FileWriter(fileName));
65 }
66
67
68 protected void logString(String msg)
69 {
70 mOutput.println(msg);
71 mOutput.flush();
72 }
73
74 public void close()
75 {
76 if(mOutput!=null)
77 mOutput.close();
78 }
79 }