Lines 1-14
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2005, 2007 Wind River Systems, Inc. and others. |
2 |
* Copyright (c) 2005, 2007 Wind River Systems, Inc. and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* Fran Litterio (Wind River) - initial API and implementation |
9 |
* Fran Litterio (Wind River) - initial API and implementation |
10 |
* Ted Williams (Wind River) - refactored into org.eclipse namespace |
10 |
* Ted Williams (Wind River) - refactored into org.eclipse namespace |
11 |
* Michael Scharf (Wind River) - split into core, view and connector plugins |
11 |
* Michael Scharf (Wind River) - split into core, view and connector plugins |
12 |
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified |
12 |
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified |
13 |
*******************************************************************************/ |
13 |
*******************************************************************************/ |
14 |
package org.eclipse.tm.internal.terminal.provisional.api; |
14 |
package org.eclipse.tm.internal.terminal.provisional.api; |
Lines 26-37
Link Here
|
26 |
* called from both class and instance methods. To use this class, write code |
26 |
* called from both class and instance methods. To use this class, write code |
27 |
* like this: |
27 |
* like this: |
28 |
* <p> |
28 |
* <p> |
29 |
* |
29 |
* |
30 |
* <pre> |
30 |
* <pre> |
31 |
* Logger.log("something has happened"); |
31 |
* Logger.log("something has happened"); |
32 |
* Logger.log("counter is " + counter); |
32 |
* Logger.log("counter is " + counter); |
33 |
* </pre> |
33 |
* </pre> |
34 |
* |
34 |
* |
35 |
* @author Fran Litterio <francis.litterio@windriver.com> |
35 |
* @author Fran Litterio <francis.litterio@windriver.com> |
36 |
* <p> |
36 |
* <p> |
37 |
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as |
37 |
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as |
Lines 72-81
Link Here
|
72 |
} |
72 |
} |
73 |
} |
73 |
} |
74 |
} |
74 |
} |
75 |
|
75 |
|
76 |
/** |
76 |
/** |
77 |
* Encodes a String such that non-printable control characters are |
77 |
* Encodes a String such that non-printable control characters are |
78 |
* converted into user-readable escape sequences for logging. |
78 |
* converted into user-readable escape sequences for logging. |
79 |
* @param message String to encode |
79 |
* @param message String to encode |
80 |
* @return encoded String |
80 |
* @return encoded String |
81 |
*/ |
81 |
*/ |
Lines 86-123
Link Here
|
86 |
char c=message.charAt(i); |
86 |
char c=message.charAt(i); |
87 |
switch(c) { |
87 |
switch(c) { |
88 |
case '\\': |
88 |
case '\\': |
89 |
case '\'': |
89 |
case '\'': |
90 |
buf.append('\\'); buf.append(c); encoded=true; |
90 |
buf.append('\\'); buf.append(c); encoded=true; |
91 |
break; |
91 |
break; |
92 |
case '\r': |
92 |
case '\r': |
93 |
buf.append('\\'); buf.append('r'); encoded=true; |
93 |
buf.append('\\'); buf.append('r'); encoded=true; |
94 |
break; |
94 |
break; |
95 |
case '\n': |
95 |
case '\n': |
96 |
buf.append('\\'); buf.append('n'); encoded=true; |
96 |
buf.append('\\'); buf.append('n'); encoded=true; |
97 |
break; |
97 |
break; |
98 |
case '\t': |
98 |
case '\t': |
99 |
buf.append('\\'); buf.append('t'); encoded=true; |
99 |
buf.append('\\'); buf.append('t'); encoded=true; |
100 |
break; |
100 |
break; |
101 |
case '\f': |
101 |
case '\f': |
102 |
buf.append('\\'); buf.append('f'); encoded=true; |
102 |
buf.append('\\'); buf.append('f'); encoded=true; |
103 |
break; |
103 |
break; |
104 |
case '\b': |
104 |
case '\b': |
105 |
buf.append('\\'); buf.append('b'); encoded=true; |
105 |
buf.append('\\'); buf.append('b'); encoded=true; |
106 |
break; |
106 |
break; |
107 |
default: |
107 |
default: |
108 |
if (c <= '\u000f') { |
108 |
if (c <= '\u000f') { |
109 |
buf.append('\\'); buf.append('x'); buf.append('0'); |
109 |
buf.append('\\'); buf.append('x'); buf.append('0'); |
110 |
buf.append(Integer.toHexString(c)); |
110 |
buf.append(Integer.toHexString(c)); |
111 |
encoded=true; |
111 |
encoded=true; |
112 |
} else if (c>=' ' && c<'\u007f') { |
112 |
} else if (c>=' ' && c<'\u007f') { |
113 |
buf.append(c); |
113 |
buf.append(c); |
114 |
} else if (c <= '\u00ff') { |
114 |
} else if (c <= '\u00ff') { |
115 |
buf.append('\\'); buf.append('x'); |
115 |
buf.append('\\'); buf.append('x'); |
116 |
buf.append(Integer.toHexString(c)); |
116 |
buf.append(Integer.toHexString(c)); |
117 |
encoded=true; |
117 |
encoded=true; |
118 |
} else { |
118 |
} else { |
119 |
buf.append('\\'); buf.append('u'); |
119 |
buf.append('\\'); buf.append('u'); |
120 |
if (c<='\u0fff') { |
120 |
if (c<='\u0fff') { |
121 |
buf.append('0'); |
121 |
buf.append('0'); |
122 |
} |
122 |
} |
123 |
buf.append(Integer.toHexString(c)); |
123 |
buf.append(Integer.toHexString(c)); |
Lines 130-136
Link Here
|
130 |
} |
130 |
} |
131 |
return message; |
131 |
return message; |
132 |
} |
132 |
} |
133 |
|
133 |
|
134 |
/** |
134 |
/** |
135 |
* Checks if logging is enabled. |
135 |
* Checks if logging is enabled. |
136 |
* @return true if logging is enabled. |
136 |
* @return true if logging is enabled. |
Lines 142-148
Link Here
|
142 |
/** |
142 |
/** |
143 |
* Logs the specified message. Do not append a newline to parameter |
143 |
* Logs the specified message. Do not append a newline to parameter |
144 |
* <i>message</i>. This method does that for you. |
144 |
* <i>message</i>. This method does that for you. |
145 |
* |
145 |
* |
146 |
* @param message A String containing the message to log. |
146 |
* @param message A String containing the message to log. |
147 |
*/ |
147 |
*/ |
148 |
public static final void log(String message) { |
148 |
public static final void log(String message) { |
Lines 168-178
Link Here
|
168 |
*/ |
168 |
*/ |
169 |
public static final void logException(Exception ex) { |
169 |
public static final void logException(Exception ex) { |
170 |
// log in eclipse error log |
170 |
// log in eclipse error log |
171 |
if(TerminalPlugin.getDefault()!=null) |
171 |
if (TerminalPlugin.getDefault() != null) { |
172 |
TerminalPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex)); |
172 |
TerminalPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex)); |
|
|
173 |
} else { |
174 |
ex.printStackTrace(); |
175 |
} |
176 |
// Additional Tracing for debug purposes: |
173 |
// Read my own stack to get the class name, method name, and line number |
177 |
// Read my own stack to get the class name, method name, and line number |
174 |
// of |
178 |
// of where this method was called |
175 |
// where this method was called. |
|
|
176 |
if(logStream!=null) { |
179 |
if(logStream!=null) { |
177 |
StackTraceElement caller = new Throwable().getStackTrace()[1]; |
180 |
StackTraceElement caller = new Throwable().getStackTrace()[1]; |
178 |
int lineNumber = caller.getLineNumber(); |
181 |
int lineNumber = caller.getLineNumber(); |
Lines 190-197
Link Here
|
190 |
+ "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ |
193 |
+ "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ |
191 |
"Caught exception: " + ex); //$NON-NLS-1$ |
194 |
"Caught exception: " + ex); //$NON-NLS-1$ |
192 |
ex.printStackTrace(tmpStream); |
195 |
ex.printStackTrace(tmpStream); |
193 |
} else { |
|
|
194 |
ex.printStackTrace(); |
195 |
} |
196 |
} |
196 |
} |
197 |
} |
197 |
} |
198 |
} |