1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* $RCSfile: JDKConsoleRenderer.java,v $
* $Revision: 1.2 $ $Date: 2005/02/15 23:05:54 $
*/
package org.eclipse.jem.util.logger.proxy;
import java.util.logging.Level;
/**
* Default log renderer to use when not running under Eclipse. It logs to sysout and syserr.
*
* @since 1.1.0
*/
public class JDKConsoleRenderer implements ILogRenderer2 {
private boolean fTraceMode = false; // will we actually punch trace messaged or not
private boolean fSettingTrace = false;
private Logger fMyLogger = null;
/**
* Constructer taking a logger.
*
* @param logger
*
* @since 1.1.0
*/
public JDKConsoleRenderer(Logger logger) {
super();
fMyLogger = logger;
fTraceMode = fMyLogger.getTraceMode();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer#log(java.lang.String, int)
*/
public String log(String msg, int type) {
if (type == ILogRenderer.LOG_TRACE && !fTraceMode)
return null;
if (type == ILogRenderer.LOG_ERROR)
System.err.println(msg);
else
System.out.println(msg);
return ILogRenderer.CONSOLE_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer#setTraceMode(boolean)
*/
public void setTraceMode(boolean flag) {
if (fSettingTrace)
return;
fSettingTrace = true;
fTraceMode = flag;
fMyLogger.setTraceMode(flag);
fSettingTrace = false;
}
/**
* Log the string at the given level.
*
* @param msg
* @param level
* @return <code>CONSOLE_DESCRIPTION</code>
*
* @since 1.1.0
*/
protected String log(String msg, Level level) {
if (level == Level.SEVERE)
System.err.println(msg);
else
System.out.println(msg);
return ILogRenderer.CONSOLE_DESCRIPTION;
}
/**
* Answer if logging at the given level
*
* @param logLevel
* @return <code>true</code> if logging at the given level.
*
* @since 1.1.0
*/
protected boolean isLogging(Level logLevel) {
return fTraceMode || fMyLogger.isLoggingLevel(logLevel);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(boolean, java.util.logging.Level)
*/
public String log(boolean b, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(b), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(byte, java.util.logging.Level)
*/
public String log(byte b, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(b), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(char, java.util.logging.Level)
*/
public String log(char c, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(c), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(double, java.util.logging.Level)
*/
public String log(double d, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(d), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(float, java.util.logging.Level)
*/
public String log(float f, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(f), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(int, java.util.logging.Level)
*/
public String log(int i, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(i), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(long, java.util.logging.Level)
*/
public String log(long l, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(l), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(java.lang.Object, java.util.logging.Level)
*/
public String log(Object o, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(o), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(short, java.util.logging.Level)
*/
public String log(short s, Level level) {
if (level == DEFAULT)
level = Level.FINEST;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(String.valueOf(s), level), level);
else
return NOLOG_DESCRIPTION;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(java.lang.Throwable, java.util.logging.Level)
*/
public String log(Throwable t, Level level) {
if (level == DEFAULT)
level = Level.SEVERE;
if (isLogging(level))
return log(fMyLogger.getGenericMsg(fMyLogger.exceptionToString(t), level), level);
else
return NOLOG_DESCRIPTION;
}
}
|