Lines 115-120
Link Here
|
115 |
ae.addRecord(rec); |
115 |
ae.addRecord(rec); |
116 |
return e; |
116 |
return e; |
117 |
} |
117 |
} |
|
|
118 |
|
119 |
/** |
120 |
* Attaches a given severity to the exception. When the exception is |
121 |
* later passed to {@link #printStackTrace} method, the level is |
122 |
* then used as a level for reported {@link LogRecord}. This allows |
123 |
* those who report exceptions to annotate them as unimportant, |
124 |
* expected. |
125 |
* |
126 |
* @param e exception to assign severity to |
127 |
* @param severity the severity |
128 |
* @since 8.8 |
129 |
*/ |
130 |
public static <E extends Throwable> E attachSeverity(E e, Level severity) { |
131 |
AnnException ae = AnnException.findOrCreate(e, true); |
132 |
ae.addRecord(new LogRecord(severity, null)); |
133 |
return e; |
134 |
} |
118 |
|
135 |
|
119 |
/** Extracts previously attached localized message for a given throwable. |
136 |
/** Extracts previously attached localized message for a given throwable. |
120 |
* Complements {@link #attachLocalizedMessage}. |
137 |
* Complements {@link #attachLocalizedMessage}. |
Lines 171-182
Link Here
|
171 |
* @param t the exception to notify |
188 |
* @param t the exception to notify |
172 |
*/ |
189 |
*/ |
173 |
public static void printStackTrace(Throwable t) { |
190 |
public static void printStackTrace(Throwable t) { |
|
|
191 |
AnnException ae = AnnException.findOrCreate(t, false); |
192 |
Level level = null; |
193 |
if (ae != null) { |
194 |
for (LogRecord r : ae.records) { |
195 |
if (r.getLevel() != Level.ALL) { |
196 |
level = r.getLevel(); |
197 |
break; |
198 |
} |
199 |
} |
200 |
} |
201 |
if (level == null) { |
202 |
level = OwnLevel.UNKNOWN; |
203 |
} |
174 |
AnnException extra = AnnException.extras.get(t); |
204 |
AnnException extra = AnnException.extras.get(t); |
175 |
if (extra != null) { |
205 |
if (extra != null) { |
176 |
assert t == extra.getCause(); |
206 |
assert t == extra.getCause(); |
177 |
t = extra; |
207 |
t = extra; |
178 |
} |
208 |
} |
179 |
LOG.log(OwnLevel.UNKNOWN, null, t); |
209 |
LOG.log(level, null, t); |
180 |
} |
210 |
} |
181 |
|
211 |
|
182 |
/** An exception that has a log record associated with itself, so |
212 |
/** An exception that has a log record associated with itself, so |
Lines 213-218
Link Here
|
213 |
private static Map<Throwable, AnnException> extras = new WeakHashMap<Throwable, AnnException>(); |
243 |
private static Map<Throwable, AnnException> extras = new WeakHashMap<Throwable, AnnException>(); |
214 |
|
244 |
|
215 |
static AnnException findOrCreate(Throwable t, boolean create) { |
245 |
static AnnException findOrCreate(Throwable t, boolean create) { |
|
|
246 |
if (t == null) { |
247 |
return null; |
248 |
} |
216 |
if (t instanceof AnnException) { |
249 |
if (t instanceof AnnException) { |
217 |
return (AnnException)t; |
250 |
return (AnnException)t; |
218 |
} |
251 |
} |