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