| 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 | | | package org.jcoderz.commons.logging; |
| 34 | | | |
| 35 | | | import java.io.PrintWriter; |
| 36 | | | import java.math.BigInteger; |
| 37 | | | import java.util.Calendar; |
| 38 | | | import java.util.Iterator; |
| 39 | | | import java.util.List; |
| 40 | | | import java.util.Set; |
| 41 | | | import java.util.TimeZone; |
| 42 | | | |
| 43 | | | import javax.xml.bind.JAXBContext; |
| 44 | | | import javax.xml.bind.JAXBException; |
| 45 | | | import javax.xml.bind.Marshaller; |
| 46 | | | |
| 47 | | | import org.apache.commons.pool.BaseKeyedPoolableObjectFactory; |
| 48 | | | import org.apache.commons.pool.impl.StackKeyedObjectPool; |
| 49 | | | import org.jcoderz.commons.util.Assert; |
| 50 | | | |
| 51 | | | |
| 52 | | | |
| 53 | | | |
| 54 | | | |
| 55 | | | |
| 56 | | | |
| 57 | | | |
| 58 | | (1) | public final class XmlPrinter |
| 59 | | | extends LogPrinter |
| 60 | | | { |
| 61 | | | private final LogRecordTypesObjectPool mXmlObjectsPool; |
| 62 | 100 | (2) | private final ObjectFactory mObjectFactory = new ObjectFactory(); |
| 63 | | | private final JAXBContext mJaxbContext; |
| 64 | | | private final Marshaller mMarshaller; |
| 65 | | | |
| 66 | 100 | | private static final class LogRecordTypesObjectPool |
| 67 | | | extends StackKeyedObjectPool |
| 68 | | | { |
| 69 | | | private LogRecordType borrowLogRecordType () |
| 70 | | | throws LoggingException |
| 71 | | | { |
| 72 | | | try |
| 73 | | | { |
| 74 | 75 | | return (LogRecordType) borrowObject(LogRecordType.class); |
| 75 | | | } |
| 76 | 0 | | catch (Exception ex) |
| 77 | | | { |
| 78 | 0 | | throw new LoggingException("Error borrowing LogRecordType", ex); |
| 79 | | | } |
| 80 | | | } |
| 81 | | | |
| 82 | | | private LogRecordType borrowLogRecord () |
| 83 | | | throws LoggingException |
| 84 | | | { |
| 85 | | | try |
| 86 | | | { |
| 87 | 100 | | return (LogRecordType) borrowObject(LogRecord.class); |
| 88 | | | } |
| 89 | 0 | | catch (Exception ex) |
| 90 | | | { |
| 91 | 0 | | throw new LoggingException("Error borrowing LogRecord", ex); |
| 92 | | | } |
| 93 | | | } |
| 94 | | | |
| 95 | | | private void returnLogRecord (final LogRecordType record) |
| 96 | | | throws LoggingException |
| 97 | | | { |
| 98 | | | try |
| 99 | | | { |
| 100 | 75 | | returnObject(LogRecordType.class, record); |
| 101 | | | } |
| 102 | 0 | | catch (Exception ex) |
| 103 | | | { |
| 104 | 0 | (3) | throw new LoggingException("Error returning LogRecordType", ex); |
| 105 | 100 | | } |
| 106 | 100 | | } |
| 107 | | | |
| 108 | | | private FrameType borrowFrame () |
| 109 | | | throws LoggingException |
| 110 | | | { |
| 111 | | | try |
| 112 | | | { |
| 113 | 100 | | return (FrameType) borrowObject(FrameType.class); |
| 114 | | | } |
| 115 | 0 | | catch (Exception ex) |
| 116 | | | { |
| 117 | 0 | | throw new LoggingException("Error borrowing FrameType", ex); |
| 118 | | | } |
| 119 | | | } |
| 120 | | | |
| 121 | | | private void returnFrame (final FrameType frame) |
| 122 | | | throws LoggingException |
| 123 | | | { |
| 124 | | | try |
| 125 | | | { |
| 126 | 75 | | returnObject(FrameType.class, frame); |
| 127 | | | } |
| 128 | 0 | | catch (Exception ex) |
| 129 | | | { |
| 130 | 0 | (4) | throw new LoggingException("Error returning FrameType", ex); |
| 131 | 100 | | } |
| 132 | 100 | | } |
| 133 | | | |
| 134 | | | private ParameterType borrowParameter () |
| 135 | | | throws LoggingException |
| 136 | | | { |
| 137 | | | try |
| 138 | | | { |
| 139 | 75 | | return (ParameterType) borrowObject(ParameterType.class); |
| 140 | | | } |
| 141 | 0 | | catch (Exception ex) |
| 142 | | | { |
| 143 | 0 | | throw new LoggingException("Error borrowing ParameterType", ex); |
| 144 | | | } |
| 145 | | | } |
| 146 | | | |
| 147 | | | private void returnParameter (final ParameterType parameter) |
| 148 | | | throws LoggingException |
| 149 | | | { |
| 150 | | | try |
| 151 | | | { |
| 152 | 75 | | returnObject(ParameterType.class, parameter); |
| 153 | | | } |
| 154 | 0 | | catch (Exception ex) |
| 155 | | | { |
| 156 | 0 | (5) | throw new LoggingException("Error returning ParameterType", ex); |
| 157 | 100 | | } |
| 158 | 100 | | } |
| 159 | | | |
| 160 | | | private CauseType borrowCause () |
| 161 | | | throws LoggingException |
| 162 | | | { |
| 163 | | | try |
| 164 | | | { |
| 165 | 75 | | return (CauseType) borrowObject(CauseType.class); |
| 166 | | | } |
| 167 | 0 | | catch (Exception ex) |
| 168 | | | { |
| 169 | 0 | | throw new LoggingException("Error borrowing CauseType", ex); |
| 170 | | | } |
| 171 | | | } |
| 172 | | | |
| 173 | | | private void returnCause (final CauseType cause) |
| 174 | | | throws LoggingException |
| 175 | | | { |
| 176 | | | try |
| 177 | | | { |
| 178 | 75 | | returnObject(CauseType.class, cause); |
| 179 | | | } |
| 180 | 0 | | catch (Exception ex) |
| 181 | | | { |
| 182 | 0 | (6) | throw new LoggingException("Error returning CauseType", ex); |
| 183 | 100 | | } |
| 184 | 100 | | } |
| 185 | | | |
| 186 | | | private ExceptionType borrowException () |
| 187 | | | throws LoggingException |
| 188 | | | { |
| 189 | | | try |
| 190 | | | { |
| 191 | 75 | | return (ExceptionType) borrowObject(ExceptionType.class); |
| 192 | | | } |
| 193 | 0 | | catch (Exception ex) |
| 194 | | | { |
| 195 | 0 | | throw new LoggingException("Error borrowing ExceptionType", ex); |
| 196 | | | } |
| 197 | | | } |
| 198 | | | |
| 199 | | | private void returnException (final ExceptionType ex) |
| 200 | | | throws LoggingException |
| 201 | | | { |
| 202 | | | try |
| 203 | | | { |
| 204 | 75 | | returnObject(ExceptionType.class, ex); |
| 205 | | | } |
| 206 | 0 | | catch (Exception ex1) |
| 207 | | | { |
| 208 | 0 | (7) | throw new LoggingException("Error returning ExceptionType", ex1); |
| 209 | 100 | | } |
| 210 | 100 | | } |
| 211 | | | |
| 212 | | | private StacktraceType borrowStacktrace () |
| 213 | | | throws LoggingException |
| 214 | | | { |
| 215 | | | try |
| 216 | | | { |
| 217 | 0 | | return (StacktraceType) borrowObject(StacktraceType.class); |
| 218 | | | } |
| 219 | 0 | | catch (Exception ex) |
| 220 | | | { |
| 221 | 0 | | throw new LoggingException("Error borrowing StacktraceType", ex); |
| 222 | | | } |
| 223 | | | } |
| 224 | | | |
| 225 | | | private void returnStacktrace (final StacktraceType stacktrace) |
| 226 | | | throws LoggingException |
| 227 | | | { |
| 228 | | | try |
| 229 | | | { |
| 230 | 0 | | returnObject(StacktraceType.class, stacktrace); |
| 231 | | | } |
| 232 | 0 | | catch (Exception ex) |
| 233 | | | { |
| 234 | 0 | (8) | throw new LoggingException("Error returning StacktraceType", ex); |
| 235 | 0 | | } |
| 236 | 0 | | } |
| 237 | | | |
| 238 | | | private Calendar borrowCalendar () |
| 239 | | | throws LoggingException |
| 240 | | | { |
| 241 | | | try |
| 242 | | | { |
| 243 | 100 | | return (Calendar) borrowObject(Calendar.class); |
| 244 | | | } |
| 245 | 0 | | catch (Exception ex) |
| 246 | | | { |
| 247 | 0 | | throw new LoggingException("Error borrowing Calendar", ex); |
| 248 | | | } |
| 249 | | | } |
| 250 | | | |
| 251 | | | private void returnCalendar (final Calendar cal) |
| 252 | | | throws LoggingException |
| 253 | | | { |
| 254 | | | try |
| 255 | | | { |
| 256 | 75 | | returnObject(Calendar.class, cal); |
| 257 | | | } |
| 258 | 0 | | catch (Exception ex) |
| 259 | | | { |
| 260 | 0 | (9) | throw new LoggingException("Error returning Calendar", ex); |
| 261 | 100 | | } |
| 262 | 100 | | } |
| 263 | | | } |
| 264 | | | |
| 265 | | | private static final class XmlObjectFactory |
| 266 | | | extends BaseKeyedPoolableObjectFactory |
| 267 | | | { |
| 268 | | | private final LogRecordTypesObjectPool mPool; |
| 269 | | | private final ObjectFactory mJaxbFactory; |
| 270 | | | |
| 271 | | | private XmlObjectFactory ( |
| 272 | | | final ObjectFactory factory, |
| 273 | | | final LogRecordTypesObjectPool pool) |
| 274 | 100 | | { |
| 275 | 100 | | mPool = pool; |
| 276 | 100 | | mJaxbFactory = factory; |
| 277 | 100 | | } |
| 278 | | | |
| 279 | | | |
| 280 | | | <code></code> |
| 281 | | | |
| 282 | | | |
| 283 | | | @param |
| 284 | | | |
| 285 | | | @return |
| 286 | | | |
| 287 | | | @see |
| 288 | | | |
| 289 | | | public Object makeObject (Object key) |
| 290 | | | throws JAXBException |
| 291 | | | { |
| 292 | | | final Object rc; |
| 293 | | | |
| 294 | 100 | | if (key == LogRecordType.class) |
| 295 | | | { |
| 296 | 100 | | rc = mJaxbFactory.createLogRecordType(); |
| 297 | | | } |
| 298 | 75 | | else if (key == LogRecord.class) |
| 299 | | | { |
| 300 | 100 | | rc = mJaxbFactory.createLogRecord(); |
| 301 | | | } |
| 302 | 75 | | else if (key == FrameType.class) |
| 303 | | | { |
| 304 | 100 | | rc = mJaxbFactory.createFrameType(); |
| 305 | | | } |
| 306 | 100 | | else if (key == StacktraceType.class) |
| 307 | | | { |
| 308 | 0 | | rc = mJaxbFactory.createStacktraceType(); |
| 309 | | | } |
| 310 | 100 | | else if (key == ParameterType.class) |
| 311 | | | { |
| 312 | 100 | | rc = mJaxbFactory.createParameterType(); |
| 313 | | | } |
| 314 | 100 | | else if (key == ExceptionType.class) |
| 315 | | | { |
| 316 | 100 | | rc = mJaxbFactory.createExceptionType(); |
| 317 | | | } |
| 318 | 100 | | else if (key == CauseType.class) |
| 319 | | | { |
| 320 | 100 | | rc = mJaxbFactory.createCauseType(); |
| 321 | | | } |
| 322 | 75 | | else if (key == Calendar.class) |
| 323 | | | { |
| 324 | 100 | | rc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| 325 | | | } |
| 326 | | | else |
| 327 | | | { |
| 328 | 0 | | throw new IllegalArgumentException("Cannot make an object for " |
| 329 | | | + key); |
| 330 | | | } |
| 331 | 100 | | return rc; |
| 332 | | | } |
| 333 | | | |
| 334 | | | |
| 335 | | | |
| 336 | | | |
| 337 | | | @param |
| 338 | | | @param |
| 339 | | | |
| 340 | | | @see |
| 341 | | | |
| 342 | | | public void activateObject (Object key, Object xmlObj) |
| 343 | | | throws LoggingException |
| 344 | | | { |
| 345 | 75 | | if ((key == LogRecordType.class) || (key == LogRecord.class)) |
| 346 | | | { |
| 347 | 100 | | final LogRecordType logRecord = (LogRecordType) xmlObj; |
| 348 | | | |
| 349 | | | |
| 350 | | | |
| 351 | 100 | | logRecord.setSource(mPool.borrowFrame()); |
| 352 | | | |
| 353 | 100 | | logRecord.setTimestamp(mPool.borrowCalendar()); |
| 354 | 100 | | } |
| 355 | 80 | | else if (key == FrameType.class) |
| 356 | | | { |
| 357 | | | |
| 358 | | | } |
| 359 | 60 | | else if (key == StacktraceType.class) |
| 360 | | | { |
| 361 | | | |
| 362 | | | } |
| 363 | 80 | | else if (key == ParameterType.class) |
| 364 | | | { |
| 365 | | | |
| 366 | | | } |
| 367 | 80 | | else if (key == ExceptionType.class) |
| 368 | | | { |
| 369 | | | |
| 370 | | | } |
| 371 | 80 | | else if (key == CauseType.class) |
| 372 | | | { |
| 373 | | | |
| 374 | | | } |
| 375 | 80 | | else if (key == Calendar.class) |
| 376 | | | { |
| 377 | | | |
| 378 | | | } |
| 379 | | | else |
| 380 | | | { |
| 381 | 0 | | throw new IllegalArgumentException("Cannot make an object for " |
| 382 | | | + key); |
| 383 | | | } |
| 384 | 100 | | } |
| 385 | | | |
| 386 | | | |
| 387 | | | |
| 388 | | | |
| 389 | | | |
| 390 | | | @param |
| 391 | | | @param |
| 392 | | | |
| 393 | | | @see |
| 394 | | | |
| 395 | | | public void passivateObject (Object key, Object jaxbObj) |
| 396 | | | throws LoggingException |
| 397 | | | { |
| 398 | 75 | | if ((key == LogRecordType.class) || (key == LogRecord.class)) |
| 399 | | | { |
| 400 | 100 | | passivateLogRecord((LogRecordType) jaxbObj); |
| 401 | | | } |
| 402 | 75 | | else if (key == FrameType.class) |
| 403 | | | { |
| 404 | 100 | | passivateFrame((FrameType) jaxbObj); |
| 405 | | | } |
| 406 | 75 | | else if (key == StacktraceType.class) |
| 407 | | | { |
| 408 | 0 | | passivateStackTrace((StacktraceType) jaxbObj); |
| 409 | | | } |
| 410 | 75 | | else if (key == ParameterType.class) |
| 411 | | | { |
| 412 | 100 | | passivateParameter((ParameterType) jaxbObj); |
| 413 | | | } |
| 414 | 75 | | else if (key == ExceptionType.class) |
| 415 | | | { |
| 416 | 100 | | passivateException((ExceptionType) jaxbObj); |
| 417 | | | } |
| 418 | 75 | | else if (key == CauseType.class) |
| 419 | | | { |
| 420 | 100 | | passivateCause((CauseType) jaxbObj); |
| 421 | | | } |
| 422 | 80 | | else if (key == Calendar.class) |
| 423 | | | { |
| 424 | | | |
| 425 | | | } |
| 426 | | | else |
| 427 | | | { |
| 428 | 0 | | throw new IllegalArgumentException("Cannot make an object for " |
| 429 | | | + key); |
| 430 | | | } |
| 431 | 100 | | } |
| 432 | | | |
| 433 | | | |
| 434 | | | <code></code> |
| 435 | | | |
| 436 | | | @param |
| 437 | | | |
| 438 | | | @throws |
| 439 | | | |
| 440 | | | private void passivateCause (final CauseType cause) |
| 441 | | | throws LoggingException |
| 442 | | | { |
| 443 | 100 | | final ExceptionType ex = cause.getException(); |
| 444 | 100 | | cause.setException(null); |
| 445 | | | |
| 446 | 100 | | final LogRecordType record = cause.getNestedRecord(); |
| 447 | 100 | | cause.setNestedRecord(null); |
| 448 | | | |
| 449 | 100 | | if (ex != null) |
| 450 | | | { |
| 451 | 100 | | mPool.returnException(ex); |
| 452 | | | } |
| 453 | 100 | | if (record != null) |
| 454 | | | { |
| 455 | 100 | | mPool.returnLogRecord(record); |
| 456 | | | } |
| 457 | 100 | | } |
| 458 | | | |
| 459 | | | |
| 460 | | | <code></code> |
| 461 | | | |
| 462 | | | @param |
| 463 | | | |
| 464 | | | @throws |
| 465 | | | |
| 466 | | | private void passivateException (final ExceptionType ex) |
| 467 | | | throws LoggingException |
| 468 | | | { |
| 469 | 100 | | ex.setMessage(null); |
| 470 | | | |
| 471 | 100 | | final CauseType cause = ex.getCause(); |
| 472 | 100 | | ex.setCause(null); |
| 473 | | | |
| 474 | 100 | | final StacktraceType stacktrace = ex.getStacktrace(); |
| 475 | 100 | | ex.setStacktrace(null); |
| 476 | | | |
| 477 | 100 | | if (cause != null) |
| 478 | | | { |
| 479 | 100 | | mPool.returnCause(cause); |
| 480 | | | } |
| 481 | 100 | | if (stacktrace != null) |
| 482 | | | { |
| 483 | 0 | | mPool.returnStacktrace(stacktrace); |
| 484 | | | } |
| 485 | 100 | | } |
| 486 | | | |
| 487 | | | |
| 488 | | | <code></code> |
| 489 | | | |
| 490 | | | @param |
| 491 | | | |
| 492 | | | private void passivateParameter (final ParameterType parameter) |
| 493 | | | { |
| 494 | 100 | | parameter.setName(null); |
| 495 | 100 | | parameter.getValue().clear(); |
| 496 | 100 | | } |
| 497 | | | |
| 498 | | | |
| 499 | | | <code></code> |
| 500 | | | |
| 501 | | | @param |
| 502 | | | |
| 503 | | | @throws |
| 504 | | | |
| 505 | | | private void passivateStackTrace (final StacktraceType stacktrace) |
| 506 | | | throws LoggingException |
| 507 | | | { |
| 508 | 0 | | for (final Iterator iter |
| 509 | 0 | | = stacktrace.getStacktraceElement().iterator(); iter.hasNext(); ) |
| 510 | | | { |
| 511 | 0 | | mPool.returnFrame((FrameType) iter.next()); |
| 512 | | | } |
| 513 | 0 | | stacktrace.getStacktraceElement().clear(); |
| 514 | 0 | | } |
| 515 | | | |
| 516 | | | |
| 517 | | | <code></code> |
| 518 | | | |
| 519 | | | @param |
| 520 | | | |
| 521 | | | @throws |
| 522 | | | |
| 523 | | | private void passivateLogRecord (final LogRecordType logRecord) |
| 524 | | | throws LoggingException |
| 525 | | | { |
| 526 | 100 | | logRecord.setBusinessImpact(null); |
| 527 | 100 | | logRecord.setCategory(null); |
| 528 | 100 | | logRecord.setInstanceId(null); |
| 529 | 100 | | logRecord.setLevel(null); |
| 530 | 100 | | logRecord.setMessage(null); |
| 531 | 100 | | logRecord.setNodeId(null); |
| 532 | 100 | | logRecord.setSolution(null); |
| 533 | 100 | | logRecord.setSymbol(null); |
| 534 | 100 | | logRecord.setTrackingNumber(null); |
| 535 | | | |
| 536 | 100 | | final Calendar cal = logRecord.getTimestamp(); |
| 537 | 100 | | logRecord.setTimestamp(null); |
| 538 | | | |
| 539 | 100 | | final StacktraceType stack = logRecord.getStacktrace(); |
| 540 | 100 | | logRecord.setStacktrace(null); |
| 541 | | | |
| 542 | 100 | | final FrameType source = logRecord.getSource(); |
| 543 | 100 | | logRecord.setSource(null); |
| 544 | | | |
| 545 | 100 | | final CauseType cause = logRecord.getCause(); |
| 546 | 100 | | logRecord.setCause(null); |
| 547 | | | |
| 548 | 100 | | if (cal != null) |
| 549 | | | { |
| 550 | 100 | | mPool.returnCalendar(cal); |
| 551 | | | } |
| 552 | 100 | | if (stack != null) |
| 553 | | | { |
| 554 | 0 | | mPool.returnStacktrace(stack); |
| 555 | | | } |
| 556 | 100 | | if (source != null) |
| 557 | | | { |
| 558 | 100 | | mPool.returnFrame(source); |
| 559 | | | } |
| 560 | 100 | | if (cause != null) |
| 561 | | | { |
| 562 | 100 | | mPool.returnCause(cause); |
| 563 | | | } |
| 564 | 100 | | for (final Iterator iter = logRecord.getParameter().iterator(); |
| 565 | 100 | | iter.hasNext(); ) |
| 566 | | | { |
| 567 | 100 | | mPool.returnParameter((ParameterType) iter.next()); |
| 568 | | | } |
| 569 | | | |
| 570 | 100 | | logRecord.getParameter().clear(); |
| 571 | 100 | | } |
| 572 | | | |
| 573 | | | |
| 574 | | | <code></code> |
| 575 | | | |
| 576 | | | @param |
| 577 | | | |
| 578 | | | @throws |
| 579 | | | |
| 580 | | | private void passivateFrame (final FrameType frame) |
| 581 | | | { |
| 582 | 100 | | frame.setSourceMethod(null); |
| 583 | 100 | | frame.setSourceClass(null); |
| 584 | 100 | | frame.setSourceLine(null); |
| 585 | 100 | | } |
| 586 | | | } |
| 587 | | | |
| 588 | | | |
| 589 | | | |
| 590 | | | |
| 591 | | | @throws |
| 592 | | | |
| 593 | | | |
| 594 | | | public XmlPrinter () |
| 595 | | | throws InstantiationException |
| 596 | | | { |
| 597 | 100 | | super(); |
| 598 | | | try |
| 599 | | | { |
| 600 | 100 | (10) | mJaxbContext = JAXBContext |
| 601 | | | .newInstance("org.jcoderz.commons.logging"); |
| 602 | 100 | | mMarshaller = mJaxbContext.createMarshaller(); |
| 603 | 100 | (11) | mMarshaller.setProperty("jaxb.formatted.output", |
| 604 | | | Boolean.valueOf(true)); |
| 605 | | | } |
| 606 | 0 | | catch (JAXBException ex) |
| 607 | | | { |
| 608 | 0 | | final InstantiationException iex |
| 609 | | | = new InstantiationException("Cannot initialize jaxb resources"); |
| 610 | 0 | | iex.initCause(ex); |
| 611 | 0 | | throw iex; |
| 612 | 100 | | } |
| 613 | 100 | | mXmlObjectsPool = new LogRecordTypesObjectPool(); |
| 614 | 100 | | mXmlObjectsPool.setFactory( |
| 615 | | | new XmlObjectFactory(mObjectFactory, mXmlObjectsPool)); |
| 616 | 100 | | } |
| 617 | | | |
| 618 | | | |
| 619 | | | |
| 620 | | | |
| 621 | | | @param |
| 622 | | | @param |
| 623 | | | <code></code> |
| 624 | | | |
| 625 | | | @see |
| 626 | | | |
| 627 | | | public void print ( |
| 628 | | | final PrintWriter printer, |
| 629 | | | final LogItem logRecord) |
| 630 | | | { |
| 631 | | | try |
| 632 | | | { |
| 633 | 100 | | Assert.notNull(printer, "Printer"); |
| 634 | 100 | | Assert.notNull(logRecord, "entry"); |
| 635 | 100 | | Assert.notNull(logRecord.getType(), "logRecord.getType()"); |
| 636 | | | |
| 637 | 100 | | LogItem logEntry = logRecord; |
| 638 | 100 | | CauseType parentsCause = null; |
| 639 | 100 | | LogRecordType rootRecord = null; |
| 640 | | | |
| 641 | 100 | | while (logEntry != null) |
| 642 | | | { |
| 643 | 100 | | if (! logEntry.isExceptionItem()) |
| 644 | | | { |
| 645 | | | final LogRecordType currentRecord; |
| 646 | | | |
| 647 | 100 | | if (rootRecord == null) |
| 648 | | | { |
| 649 | 100 | | currentRecord = mXmlObjectsPool.borrowLogRecord(); |
| 650 | 100 | | rootRecord = currentRecord; |
| 651 | | | } |
| 652 | | | else |
| 653 | | | { |
| 654 | 100 | | currentRecord = mXmlObjectsPool.borrowLogRecordType(); |
| 655 | | | } |
| 656 | 100 | | fillLogRecord(currentRecord, logEntry); |
| 657 | | | |
| 658 | 100 | | if (parentsCause != null) |
| 659 | | | { |
| 660 | 100 | | parentsCause.setNestedRecord(currentRecord); |
| 661 | | | } |
| 662 | 100 | | logEntry = logEntry.getNestedItem(); |
| 663 | 100 | | parentsCause = setCause(logEntry, currentRecord); |
| 664 | 100 | | } |
| 665 | | | else |
| 666 | | | { |
| 667 | 100 | | final ExceptionType currentException |
| 668 | | | = mXmlObjectsPool.borrowException(); |
| 669 | 100 | | fillException(currentException, logEntry); |
| 670 | 100 | | if (parentsCause != null) |
| 671 | | | { |
| 672 | 100 | | parentsCause.setException(currentException); |
| 673 | | | } |
| 674 | 100 | | logEntry = logEntry.getNestedItem(); |
| 675 | 100 | | parentsCause = setCause(logEntry, currentException); |
| 676 | 100 | | } |
| 677 | | | } |
| 678 | 100 | | if (rootRecord != null) |
| 679 | | | { |
| 680 | 100 | | mMarshaller.marshal(rootRecord, printer); |
| 681 | 100 | | mXmlObjectsPool.returnLogRecord(rootRecord); |
| 682 | | | } |
| 683 | | | } |
| 684 | 0 | | catch (Exception ex) |
| 685 | | | { |
| 686 | 0 | (12) | System.err.println("Error formatting log file entry into xml: " + ex); |
| 687 | 0 | (13) | ex.printStackTrace(); |
| 688 | 100 | | } |
| 689 | 100 | | } |
| 690 | | | |
| 691 | | | private void fillLogRecord ( |
| 692 | | | final LogRecordType logRecord, |
| 693 | | | final LogItem entry) |
| 694 | | | { |
| 695 | 100 | | logRecord.setNodeId(entry.getNodeId()); |
| 696 | 100 | | logRecord.setInstanceId(entry.getInstanceId()); |
| 697 | 100 | | logRecord.setLevel(entry.getLoggerLevel().toString()); |
| 698 | 100 | | logRecord.setSymbol(entry.getSymbol()); |
| 699 | 100 | | logRecord.setSymbolId(entry.getSymbolId()); |
| 700 | | | |
| 701 | | | |
| 702 | | | |
| 703 | 100 | | logRecord.getTimestamp().setTime(entry.getTimestamp().toUtilDate()); |
| 704 | | | |
| 705 | 100 | | logRecord.setTrackingNumber(entry.getTrackingNumber()); |
| 706 | | | |
| 707 | 100 | | logRecord.getSource().setSourceClass( |
| 708 | | | entry.getSourceClass()); |
| 709 | 100 | | logRecord.getSource().setSourceMethod( |
| 710 | | | entry.getSourceMethod()); |
| 711 | 100 | | logRecord.setThread(entry.getThreadId()); |
| 712 | 100 | | logRecord.setThreadName(entry.getThreadName()); |
| 713 | 100 | | logRecord.setMessage(entry.getMessage()); |
| 714 | 100 | | logRecord.setSolution(entry.getSolution()); |
| 715 | 100 | | logRecord.setBusinessImpact( |
| 716 | | | entry.getBusinessImpact().toString()); |
| 717 | 100 | | logRecord.setCategory( |
| 718 | | | entry.getCategory().toString()); |
| 719 | | | |
| 720 | 100 | | logRecord.setMessage(entry.getMessage()); |
| 721 | | | |
| 722 | 100 | | final Set params = entry.getParameterNames(); |
| 723 | 100 | | for (final Iterator iter = params.iterator(); iter.hasNext(); ) |
| 724 | | | { |
| 725 | 100 | | final String parameterName = (String) iter.next(); |
| 726 | 100 | | final ParameterType param |
| 727 | | | = mXmlObjectsPool.borrowParameter(); |
| 728 | | | |
| 729 | 100 | | param.setName(parameterName); |
| 730 | 100 | | final List values |
| 731 | | | = entry.getParameterValues(parameterName); |
| 732 | 100 | | if (values != null) |
| 733 | | | { |
| 734 | 100 | | for (final Iterator valueIter = values.iterator(); |
| 735 | 100 | | valueIter.hasNext(); ) |
| 736 | | | { |
| 737 | 100 | | param.getValue().add(valueIter.next().toString()); |
| 738 | | | } |
| 739 | | | } |
| 740 | 100 | | logRecord.getParameter().add(param); |
| 741 | 100 | | } |
| 742 | 100 | | fillStacktrace(logRecord, entry); |
| 743 | 100 | | } |
| 744 | | | |
| 745 | | | |
| 746 | | | |
| 747 | | | |
| 748 | | | @param |
| 749 | | | @param |
| 750 | | | |
| 751 | | | private void fillStacktrace (LogRecordType logRecord, LogItem entry) |
| 752 | | | { |
| 753 | 100 | | if (displayStackTrace(entry)) |
| 754 | | | { |
| 755 | 0 | | logRecord.setStacktrace(getStackTrace(entry)); |
| 756 | | | } |
| 757 | 100 | | } |
| 758 | | | |
| 759 | | | private void fillException ( |
| 760 | | | final ExceptionType exception, |
| 761 | | | final LogItem entry) |
| 762 | | | { |
| 763 | 100 | | exception.setMessage(entry.getMessage()); |
| 764 | 100 | | if (displayStackTrace(entry)) |
| 765 | | | { |
| 766 | 100 | | exception.setStacktrace(getStackTrace(entry)); |
| 767 | | | } |
| 768 | 100 | | } |
| 769 | | | |
| 770 | | | private StacktraceType getStackTrace (final LogItem entry) |
| 771 | | | { |
| 772 | | | final StacktraceType rc; |
| 773 | 100 | | if (entry.getStackTraceLines().isEmpty()) |
| 774 | | | { |
| 775 | 100 | | rc = null; |
| 776 | | | } |
| 777 | | | else |
| 778 | | | { |
| 779 | 0 | | rc = mXmlObjectsPool.borrowStacktrace(); |
| 780 | 0 | | fillStackTrace(rc, entry); |
| 781 | | | } |
| 782 | 100 | | return rc; |
| 783 | | | } |
| 784 | | | |
| 785 | | | private void fillStackTrace ( |
| 786 | | | final StacktraceType stack, |
| 787 | | | final LogItem entry) |
| 788 | | | { |
| 789 | 0 | | for (final Iterator iter = entry.getStackTraceLines().iterator(); |
| 790 | 0 | | iter.hasNext(); ) |
| 791 | | | { |
| 792 | 0 | | final StackTraceInfo info = (StackTraceInfo) iter.next(); |
| 793 | | | |
| 794 | | | |
| 795 | | | |
| 796 | 0 | | if (info.isLocationLine()) |
| 797 | | | { |
| 798 | 0 | | final FrameType frame = mXmlObjectsPool.borrowFrame(); |
| 799 | 0 | | frame.setSourceClass(info.getClassName()); |
| 800 | 0 | | frame.setSourceMethod(info.getMethodName()); |
| 801 | 0 | | if (info.getLine() != 0) |
| 802 | | | { |
| 803 | 0 | | frame.setSourceLine(BigInteger.valueOf(info.getLine())); |
| 804 | | | } |
| 805 | 0 | | stack.getStacktraceElement().add(frame); |
| 806 | 0 | | } |
| 807 | 0 | | else if (info.isMoreLine()) |
| 808 | | | { |
| 809 | 0 | | Assert.assertTrue(info + " must be last line of a StackTrace,", |
| 810 | | | ! iter.hasNext()); |
| 811 | 0 | | fillMoreStackTrace(entry, stack, info); |
| 812 | | | } |
| 813 | 0 | | } |
| 814 | 0 | | } |
| 815 | | | |
| 816 | | | |
| 817 | | | |
| 818 | | | |
| 819 | | | |
| 820 | | | |
| 821 | | | @param |
| 822 | | | @param |
| 823 | | | |
| 824 | | | @param <code></code> |
| 825 | | | |
| 826 | | | private void fillMoreStackTrace ( |
| 827 | | | final LogItem entry, |
| 828 | | | final StacktraceType stack, |
| 829 | | | final StackTraceInfo info) |
| 830 | | | { |
| 831 | 0 | | final LogItem stackTraceEntry |
| 832 | | | = getEntryForMoreStackTrace(entry, info); |
| 833 | 0 | | if (stackTraceEntry == null) |
| 834 | | | { |
| 835 | 0 | | throw new IllegalStateException("Did not find correct stack trace to " |
| 836 | | | + "display for " + entry); |
| 837 | | | } |
| 838 | 0 | | else if (entry == stackTraceEntry) |
| 839 | | | { |
| 840 | | | |
| 841 | | | |
| 842 | 0 | | final FrameType frame = mXmlObjectsPool.borrowFrame(); |
| 843 | 0 | | frame.setSourceClass(info.toString()); |
| 844 | 0 | | frame.setSourceMethod(""); |
| 845 | 0 | | stack.getStacktraceElement().add(frame); |
| 846 | 0 | | } |
| 847 | | | else |
| 848 | | | { |
| 849 | 0 | | fillStackTrace(stack, stackTraceEntry); |
| 850 | | | } |
| 851 | 0 | | } |
| 852 | | | |
| 853 | | | private CauseType setCause ( |
| 854 | | | final LogItem entry, |
| 855 | | | final LogRecordType record) |
| 856 | | | { |
| 857 | | | final CauseType rc; |
| 858 | 100 | | if (entry != null) |
| 859 | | | { |
| 860 | 100 | | rc = mXmlObjectsPool.borrowCause(); |
| 861 | 100 | | record.setCause(rc); |
| 862 | | | } |
| 863 | | | else |
| 864 | | | { |
| 865 | 100 | | rc = null; |
| 866 | | | } |
| 867 | 100 | | return rc; |
| 868 | | | } |
| 869 | | | |
| 870 | | | private CauseType setCause ( |
| 871 | | | final LogItem entry, |
| 872 | | | final ExceptionType exception) |
| 873 | | | { |
| 874 | | | final CauseType rc; |
| 875 | 100 | | if (entry != null) |
| 876 | | | { |
| 877 | 100 | | rc = mXmlObjectsPool.borrowCause(); |
| 878 | 100 | | exception.setCause(rc); |
| 879 | | | } |
| 880 | | | else |
| 881 | | | { |
| 882 | 100 | | rc = null; |
| 883 | | | } |
| 884 | 100 | | return rc; |
| 885 | | | } |
| 886 | | | } |