1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jdo.impl.enhancer;
18
19 import java.io.PrintWriter;
20
21 import org.apache.jdo.impl.enhancer.util.Support;
22
23
24
25 /***
26 * Provides some basic utilities for main classes.
27 *
28 * @author Martin Zaun
29 */
30 class LogSupport
31 extends Support
32 {
33 /***
34 * The stream to write messages to.
35 */
36 protected final PrintWriter out;
37
38 /***
39 * The stream to write error messages to.
40 */
41 protected final PrintWriter err;
42
43 /***
44 * Creates an instance.
45 */
46 public LogSupport(PrintWriter out,
47 PrintWriter err)
48 {
49 affirm(out != null);
50 affirm(err != null);
51 this.out = out;
52 this.err = err;
53 }
54
55 /***
56 * Prints out an error message.
57 */
58 protected void printlnErr(String msg,
59 Throwable ex,
60 boolean verbose)
61 {
62 out.flush();
63 if (msg != null) {
64 err.println(msg);
65 }
66 if (ex != null) {
67 if (verbose) {
68 ex.printStackTrace(err);
69 }
70 else {
71 err.println(ex.toString());
72 }
73 }
74 }
75
76 /***
77 * Prints out an error message.
78 */
79 protected void printlnErr(String msg,
80 Throwable ex)
81 {
82 out.flush();
83 err.println(msg + ": " + ex.getMessage());
84 ex.printStackTrace(err);
85 }
86
87 /***
88 * Prints out an error message.
89 */
90 protected void printlnErr(String msg)
91 {
92 out.flush();
93 err.println(msg);
94 }
95
96 /***
97 * Prints out an error message.
98 */
99 protected void printlnErr()
100 {
101 out.flush();
102 err.println();
103 }
104
105 /***
106 * Prints out a message.
107 */
108 protected void print(String msg)
109 {
110 out.print(msg);
111 }
112
113 /***
114 * Prints out a message.
115 */
116 protected void println(String msg)
117 {
118 out.println(msg);
119 }
120
121 /***
122 * Prints out a message.
123 */
124 protected void println()
125 {
126 out.println();
127 }
128
129 /***
130 * Flushes streams.
131 */
132 protected void flush()
133 {
134 out.flush();
135 err.flush();
136 }
137
138
139
140
141
142 /***
143 * Prints out a warning message.
144 *
145 * @param msg the message
146 */
147
148
149
150
151
152
153 /***
154 * Prints out a verbose message.
155 *
156 * @param msg the message
157 */
158
159
160
161
162
163
164
165
166 }