this.cause = new ThrowableProxy(nested); this.cause.commonFrames = ThrowableProxyUtil.findNumberOfCommonFrames(nested.getStackTrace(), stackTraceElementProxyArray); suppressed = new ThrowableProxy[throwableSuppressed.length]; for (int i = 0; i < throwableSuppressed.length; i++) { this.suppressed[i] = new ThrowableProxy(throwableSuppressed[i]); this.suppressed[i].commonFrames = ThrowableProxyUtil.findNumberOfCommonFrames(throwableSuppressed[i].getStackTrace(), stackTraceElementProxyArray);
public LoggingEvent(String fqcn, Logger logger, Level level, String message, Throwable throwable, Object[] argArray) { this.fqnOfLoggerClass = fqcn; this.loggerName = logger.getName(); this.loggerContext = logger.getLoggerContext(); this.loggerContextVO = loggerContext.getLoggerContextRemoteView(); this.level = level; this.message = message; this.argumentArray = argArray; if (throwable == null) { throwable = extractThrowableAnRearrangeArguments(argArray); } if (throwable != null) { this.throwableProxy = new ThrowableProxy(throwable); LoggerContext lc = logger.getLoggerContext(); if (lc.isPackagingDataEnabled()) { this.throwableProxy.calculatePackagingData(); } } timeStamp = System.currentTimeMillis(); }
@Test public void testStack() { Exception ex = new UnsupportedOperationException("foo"); ex = new IllegalStateException("bar", ex); StringBuilder stackBuilder = new StringBuilder(); LoggingAppender.writeStack(new ThrowableProxy(ex), "", stackBuilder); String stack = stackBuilder.toString(); assertThat(stack).contains("java.lang.IllegalStateException: bar"); assertThat(stack).contains("caused by: java.lang.UnsupportedOperationException: foo"); assertThat(stack).contains("common frames elided"); } }
this.cause = new ThrowableProxy(nested); this.cause.commonFrames = ThrowableProxyUtil .findNumberOfCommonFrames(nested.getStackTrace(), suppressed = new ThrowableProxy[throwableSuppressed.length]; for(int i=0;i<throwableSuppressed.length;i++) { this.suppressed[i] = new ThrowableProxy(throwableSuppressed[i]); this.suppressed[i].commonFrames = ThrowableProxyUtil .findNumberOfCommonFrames(throwableSuppressed[i].getStackTrace(),
public LoggingEvent(String fqcn, Logger logger, Level level, String message, Throwable throwable, Object[] argArray) { this.fqnOfLoggerClass = fqcn; this.loggerName = logger.getName(); this.loggerContext = logger.getLoggerContext(); this.loggerContextVO = loggerContext.getLoggerContextRemoteView(); this.level = level; this.message = message; this.argumentArray = argArray; if(throwable == null) { throwable = extractThrowableAnRearrangeArguments(argArray); } if (throwable != null) { this.throwableProxy = new ThrowableProxy(throwable); LoggerContext lc = logger.getLoggerContext(); if (lc.isPackagingDataEnabled()) { this.throwableProxy.calculatePackagingData(); } } timeStamp = System.currentTimeMillis(); }
public ThrowableProxy(Throwable throwable) { this.throwable = throwable; this.className = throwable.getClass().getName(); this.message = throwable.getMessage(); this.stackTraceElementProxyArray = ThrowableProxyUtil.steArrayToStepArray(throwable .getStackTrace()); Throwable nested = throwable.getCause(); if (nested != null) { this.cause = new ThrowableProxy(nested); this.cause.commonFrames = ThrowableProxyUtil .findNumberOfCommonFrames(nested.getStackTrace(), stackTraceElementProxyArray); } }
ThrowableProxy getThrowableProxy(Throwable t) { if (t == null) return null; ThrowableProxy throwableProxy = new ThrowableProxy(t); if (loggerContext.isPackagingDataEnabled()) { throwableProxy.calculatePackagingData(); } return throwableProxy; }
public void verify(Throwable t) { t.printStackTrace(pw); IThrowableProxy tp = new ThrowableProxy(t); String result = ThrowableProxyUtil.asString(tp); result = result.replace("common frames omitted", "more"); String expected = sw.toString(); System.out.println("========expected"); System.out.println(expected); System.out.println("========result"); System.out.println(result); assertEquals(expected, result); }
private LoggingEvent makeEvent(Level level, String message, Throwable th) { LoggingEvent event = new LoggingEvent(); event.setLoggerName(CloudWatchAppender.class.getName()); event.setLevel(level); event.setMessage(message); event.setTimeStamp(System.currentTimeMillis()); if (th != null) { event.setThrowableProxy(new ThrowableProxy(th)); } return event; } }
private LoggingEvent makeEvent(Level level, String message, Throwable th) { LoggingEvent event = new LoggingEvent(); event.setLoggerName(CloudWatchAppender.class.getName()); event.setLevel(level); event.setMessage(message); event.setTimeStamp(System.currentTimeMillis()); if (th != null) { event.setThrowableProxy(new ThrowableProxy(th)); } return event; } }
@Test public void testAddException() throws Exception { //given final Exception throwable = new Exception("Some exception"); final StringWriter stringWriter = new StringWriter(); throwable.printStackTrace(new PrintWriter(stringWriter)); ThrowableProxy throwableProxy = new ThrowableProxy(throwable); //when LogbackUtil.addException(throwableProxy,"Message!", builder); //then final LogData logData = builder.build(); assertEquals(logData.getMessage(), "Message!\n" + stringWriter.getBuffer().toString()); }
public void verifyContains(Throwable t, String expected) { IThrowableProxy tp = new ThrowableProxy(t); String result = ThrowableProxyUtil.asString(tp); assertTrue("Did not find '" + expected + "' in \n" + result, result.contains(expected)); }
private void nesting() { throwable = new Throwable("x"); throwableProxy = new ThrowableProxy(throwable); PackagingDataCalculator pdc = new PackagingDataCalculator(); pdc.calculate(throwableProxy); }
public void doCalculateClassPackagingData( boolean withClassPackagingCalculation) { try { throw new Exception("testing"); } catch (Throwable e) { ThrowableProxy tp = new ThrowableProxy(e); if (withClassPackagingCalculation) { PackagingDataCalculator pdc = tp.getPackagingDataCalculator(); pdc.calculate(tp); } } }
@Test // Test http://jira.qos.ch/browse/LBCLASSIC-125 public void noClassDefFoundError_LBCLASSIC_125Test() throws MalformedURLException { ClassLoader cl = (URLClassLoader) makeBogusClassLoader(); Thread.currentThread().setContextClassLoader(cl); Throwable t = new Throwable("x"); ThrowableProxy tp = new ThrowableProxy(t); StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray(); StackTraceElement bogusSTE = new StackTraceElement("com.Bogus", "myMethod", "myFile", 12); stepArray[0] = new StackTraceElementProxy(bogusSTE); PackagingDataCalculator pdc = tp.getPackagingDataCalculator(); // NoClassDefFoundError should be caught pdc.calculate(tp); }
@Test public void smoke() throws Exception { Throwable t = new Throwable("x"); ThrowableProxy tp = new ThrowableProxy(t); PackagingDataCalculator pdc = tp.getPackagingDataCalculator(); pdc.calculate(tp); verify(tp); tp.fullDump(); }
@Test public void extendendeThrowable() throws Exception { LoggingEvent event = createLoggingEvent(); Throwable throwable = new Throwable("just testing"); ThrowableProxy tp = new ThrowableProxy(throwable); event.setThrowableProxy(tp); tp.calculatePackagingData(); ILoggingEvent remoteEvent = writeAndRead(event); checkForEquality(event, remoteEvent); }
@Test public void nested() throws Exception { Throwable t = TestHelper.makeNestedException(3); ThrowableProxy tp = new ThrowableProxy(t); PackagingDataCalculator pdc = tp.getPackagingDataCalculator(); pdc.calculate(tp); verify(tp); }
@Test public void tagExcludesStackTraces() { // create logging event with throwable LoggingEvent event = new LoggingEvent(); Throwable throwable = new Throwable("throwable"); ThrowableProxy tp = new ThrowableProxy(throwable); event.setThrowableProxy(tp); event.setMessage(TAG); setTagPattern(TAG, true); // if the tags match, it does not include the stack trace String actualTag = logcatAppender.getTagEncoder().getLayout().doLayout(event); assertThat(TAG, is(actualTag)); }
private LogStatement makeRandomLogStatement(String[] loggerNamePool) { MessageArgumentTuple mat = makeRandomMessageArgumentTuple(); String loggerName = getRandomLoggerNameFromPool(loggerNamePool); Level randomLevel = getRandomLevel(); Throwable t = getRandomThrowable(randomLevel); ThrowableProxyVO throwableProxy = null; if (t != null) { throwableProxy = ThrowableProxyVO.build(new ThrowableProxy(t)); pupulateWithPackagingData(throwableProxy.getStackTraceElementProxyArray()); } return new LogStatement(loggerName, randomLevel, mat, throwableProxy); }