ch.qos.logback.classic.spi.IThrowableProxy Java Examples

The following examples show how to use ch.qos.logback.classic.spi.IThrowableProxy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: jframework   Author: micro-jframework   File: DingTalkAppender.java    License: Apache License 2.0 6 votes vote down vote up
private String transformStackTrace(ILoggingEvent event) {
    String exception = "";
    IThrowableProxy throwableProxy =  event.getThrowableProxy();
    if (throwableProxy != null) {
        exception = ThrowableProxyUtil.asString(throwableProxy);
    }

    StackTraceElement[] callerData = event.getCallerData();
    StackTraceElement stackTraceElement = callerData[0];

    String time = DEFAULT_DATE_FORMAT.format(new Date(event.getTimeStamp()));
    String threadName = event.getThreadName();
    String level = event.getLevel().toString();
    String logger = event.getLoggerName();
    String msg = event.getFormattedMessage();
    String className = stackTraceElement.getClassName();
    String method = stackTraceElement.getMethodName();
    int lineNumber = stackTraceElement.getLineNumber();

    return String.format(FORMAT_MESSAGE, time, threadName, level, logger, className, method, lineNumber, exception, msg);
}
 
Example #2
Source Project: arcusplatform   Author: arcus-smart-home   File: Gateway.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void appendLogEntry(ILoggingEvent event) {
   JsonObject object = new JsonObject();
   for(Map.Entry<String, String> e: event.getMDCPropertyMap().entrySet()) {
      object.addProperty(e.getKey(), e.getValue());
   }

   object.addProperty("ts", event.getTimeStamp());
   object.addProperty("lvl", event.getLevel().toString());
   object.addProperty("thd", event.getThreadName());
   object.addProperty("log", event.getLoggerName());
   object.addProperty("msg", event.getFormattedMessage());

   IThrowableProxy thrw = event.getThrowableProxy();
   if (thrw != null) {
      String stackTrace = converter.convert(event);
      object.addProperty("exc", stackTrace);
   } else {
      object.remove("exc");
   }

   if (!bufferedLogMessages.offer(object)) {
      log.trace("log message dropped because queue overflowed");
   }
}
 
Example #3
Source Project: DimpleBlog   Author: DimpleFeng   File: LogFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
    StringBuilder exception = new StringBuilder();
    IThrowableProxy iThrowableProxy1 = event.getThrowableProxy();
    if (iThrowableProxy1 != null) {
        exception.append("<span class='excehtext'>" + iThrowableProxy1.getClassName() + " " + iThrowableProxy1.getMessage() + "</span></br>");
        for (int i = 0; i < iThrowableProxy1.getStackTraceElementProxyArray().length; i++) {
            exception.append("<span class='excetext'>" + iThrowableProxy1.getStackTraceElementProxyArray()[i].toString() + "</span></br>");
        }
    }
    LoggerMessage loggerMessage = new LoggerMessage(
            event.getMessage()
            , DateFormat.getDateTimeInstance().format(new Date(event.getTimeStamp())),
            event.getThreadName(),
            event.getLoggerName(),
            event.getLevel().levelStr,
            exception.toString(),
            ""
    );
    LoggerQueue.getInstance().push(loggerMessage);
    return FilterReply.ACCEPT;
}
 
Example #4
Source Project: cloudwatch-logback-appender   Author: dibog   File: ExceptionUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static void appendProxy(StringBuilder sb, String aPrefix, String aHeader, IThrowableProxy aException) {

        sb.append(aPrefix + aHeader + aException.getClassName() + ": " +aException.getMessage() + "\n");

        String prefix = aPrefix+"\t";
        appendStackTrace(sb, prefix, aException);

        IThrowableProxy[] suppressed = aException.getSuppressed();
        if(suppressed!=null) {
            for(IThrowableProxy supp : suppressed) {
                if(supp!=null) {
                    appendProxy(sb, prefix, "Suppressed: ", supp);
                }
            }
        }

        IThrowableProxy cause = aException.getCause();
        if(cause!=null) {
            appendProxy(sb, prefix, "Causd by: ", cause);
        }
    }
 
Example #5
Source Project: java-spring-cloud   Author: opentracing-contrib   File: SpanLogsAppender.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This is called only for configured levels.
 * It will not be executed for DEBUG level if root logger is INFO.
 */
@Override
protected void append(ILoggingEvent event) {
  Span span = tracer.activeSpan();
  if (span != null) {
    Map<String, Object> logs = new HashMap<>(6);
    logs.put("logger", event.getLoggerName());
    logs.put("level", event.getLevel().toString());
    logs.put("thread", event.getThreadName());
    logs.put("message", event.getFormattedMessage());

    if (Level.ERROR.equals(event.getLevel())) {
      logs.put("event", Tags.ERROR);
    }

    IThrowableProxy throwableProxy = event.getThrowableProxy();
    if (throwableProxy instanceof ThrowableProxy) {
      Throwable throwable = ((ThrowableProxy)throwableProxy).getThrowable();
      // String stackTrace = ThrowableProxyUtil.asString(throwableProxy);
      if (throwable != null) {
        logs.put("error.object", throwable);
      }
    }
    span.log(TimeUnit.MICROSECONDS.convert(event.getTimeStamp(), TimeUnit.MILLISECONDS), logs);
  }
}
 
Example #6
Source Project: cachecloud   Author: sohutv   File: ErrorStatisticsAppender.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    if (event == null) {
        return;
    }
    if (event.getLevel() == Level.ERROR || event.getLevel() == Level.WARN) {
        IThrowableProxy throwableProxy = event.getThrowableProxy();
        if (throwableProxy != null) {
        	//接口名
            String errorClassName = throwableProxy.getClassName();
            if (errorClassName != null && !"".equals(errorClassName.trim())) {
            	//写入AtomicLongMap并计数
                ERROR_NAME_VALUE_MAP.getAndIncrement(errorClassName);
            }
        }
    }
}
 
Example #7
Source Project: bither-desktop-java   Author: bither   File: PrefixedThrowableProxyConverter.java    License: Apache License 2.0 6 votes vote down vote up
void subjoinThrowableProxy(StringBuilder buf, IThrowableProxy tp) {
    subjoinFirstLine(buf, tp);


    buf.append(CoreConstants.LINE_SEPARATOR);
    final StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
    final int commonFrames = tp.getCommonFrames();

    int maxIndex = stepArray.length;
    if (commonFrames > 0) {
        maxIndex -= commonFrames;
    }

    for (int i = 0; i < maxIndex; i++) {
        final String string = stepArray[i].toString();
        buf.append(PREFIX);
        buf.append(string);
        extraData(buf, stepArray[i]); // allow other data to be added
        buf.append(CoreConstants.LINE_SEPARATOR);
    }

    if (commonFrames > 0) {
        buf.append("!... ").append(tp.getCommonFrames()).append(
                " common frames omitted").append(CoreConstants.LINE_SEPARATOR);
    }
}
 
Example #8
Source Project: flo   Author: spotify   File: StructuredLoggingEncoder.java    License: Apache License 2.0 6 votes vote down vote up
private static void writeStack(StringBuilder sb, IThrowableProxy t, String caption, int indent, String linebreak) {
  if (t == null) {
    return;
  }
  indent(sb, indent).append(caption).append(t.getClassName()).append(": ").append(t.getMessage()).append(linebreak);
  final StackTraceElementProxy[] trace = t.getStackTraceElementProxyArray();
  if (trace != null) {
    int commonFrames = t.getCommonFrames();
    int printFrames = trace.length - commonFrames;
    for (int i = 0; i < printFrames; i++) {
      indent(sb, indent).append("\t").append(trace[i]).append(linebreak);
    }
    if (commonFrames != 0) {
      indent(sb, indent).append("\t... ").append(commonFrames).append(" more").append(linebreak);
    }
    final IThrowableProxy[] suppressed = t.getSuppressed();
    for (IThrowableProxy st : suppressed) {
      writeStack(sb, st, "Suppressed: ", indent + 1, linebreak);
    }
  }

  writeStack(sb, t.getCause(), "Caused by: ", indent, linebreak);
}
 
Example #9
Source Project: glowroot   Author: glowroot   File: CollectorLogbackAppender.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    if (inFlush.get()) {
        return;
    }
    if (event.getLevel() == Level.DEBUG && event.getLoggerName().startsWith("io.grpc.")) {
        return;
    }
    if (event.getLoggerName().startsWith("org.glowroot.central.")
            || event.getLoggerName().startsWith("org.glowroot.ui.")) {
        // this can happen during integration tests when agent and the central collector are
        // running in the same JVM (using LocalContainer for agent)
        return;
    }
    LogEvent.Builder builder = LogEvent.newBuilder()
            .setTimestamp(event.getTimeStamp())
            .setLevel(toProto(event.getLevel()))
            .setLoggerName(event.getLoggerName())
            .setMessage(event.getFormattedMessage());
    IThrowableProxy throwable = event.getThrowableProxy();
    if (throwable != null) {
        builder.setThrowable(toProto(throwable));
    }
    flush(builder.build());
}
 
Example #10
Source Project: glowroot   Author: glowroot   File: CollectorLogbackAppender.java    License: Apache License 2.0 6 votes vote down vote up
private static Proto.Throwable toProto(IThrowableProxy t) {
    Proto.Throwable.Builder builder = Proto.Throwable.newBuilder()
            .setClassName(t.getClassName());
    String message = t.getMessage();
    if (message != null) {
        builder.setMessage(message);
    }
    for (StackTraceElementProxy element : t.getStackTraceElementProxyArray()) {
        builder.addStackTraceElement(ErrorMessage.toProto(element.getStackTraceElement()));
    }
    builder.setFramesInCommonWithEnclosing(t.getCommonFrames());
    IThrowableProxy cause = t.getCause();
    if (cause != null) {
        builder.setCause(toProto(cause));
    }
    for (IThrowableProxy suppressed : t.getSuppressed()) {
        builder.addSuppressed(toProto(suppressed));
    }
    return builder.build();
}
 
Example #11
Source Project: bither-desktop-java   Author: bither   File: PrefixedThrowableProxyConverter.java    License: Apache License 2.0 6 votes vote down vote up
void subjoinThrowableProxy(StringBuilder buf, IThrowableProxy tp) {
    subjoinFirstLine(buf, tp);


    buf.append(CoreConstants.LINE_SEPARATOR);
    final StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
    final int commonFrames = tp.getCommonFrames();

    int maxIndex = stepArray.length;
    if (commonFrames > 0) {
        maxIndex -= commonFrames;
    }

    for (int i = 0; i < maxIndex; i++) {
        final String string = stepArray[i].toString();
        buf.append(PREFIX);
        buf.append(string);
        extraData(buf, stepArray[i]); // allow other data to be added
        buf.append(CoreConstants.LINE_SEPARATOR);
    }

    if (commonFrames > 0) {
        buf.append("!... ").append(tp.getCommonFrames()).append(
                " common frames omitted").append(CoreConstants.LINE_SEPARATOR);
    }
}
 
Example #12
Source Project: logging-java   Author: spotify   File: MillisecondPrecisionSyslogAppender.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void postProcess(final Object eventObject, final OutputStream sw) {
  if (isThrowableExcluded()) {
    return;
  }

  final ILoggingEvent event = (ILoggingEvent) eventObject;
  final IThrowableProxy tp = event.getThrowableProxy();

  if (tp == null) {
    return;
  }

  final String stackTracePrefix = stackTraceLayout.doLayout(event);
  recursiveWrite(sw, stackTracePrefix, tp, 0, null);
}
 
Example #13
Source Project: NationStatesPlusPlus   Author: NationStates   File: LoggingFilter.java    License: MIT License 6 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
	final IThrowableProxy throwableProxy = event.getThrowableProxy();
	if (throwableProxy == null) {
		return FilterReply.NEUTRAL;
	}

	if (!(throwableProxy instanceof ThrowableProxy)) {
		return FilterReply.NEUTRAL;
	}

	final ThrowableProxy throwableProxyImpl = (ThrowableProxy) throwableProxy;
	final Throwable throwable = throwableProxyImpl.getThrowable();
	if (java.nio.channels.ClosedChannelException.class.isInstance(throwable)) {
		return FilterReply.DENY;
	}

	return FilterReply.NEUTRAL;
}
 
Example #14
Source Project: elexis-3-core   Author: elexis   File: IntegrationPostHandler.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private String parseException(ILoggingEvent eventObject2){
	if (eventObject.getThrowableProxy() != null) {
		StringBuilder sbException = new StringBuilder();
		IThrowableProxy throwableProxy = eventObject.getThrowableProxy();
		
		sbException.append("```\n");
		StackTraceElementProxy[] st = throwableProxy.getStackTraceElementProxyArray();
		for (int j = 0; j < st.length; j++) {
			StackTraceElementProxy stackTraceElementProxy = st[j];
			StackTraceElement stackTraceElement = stackTraceElementProxy.getStackTraceElement();
			sbException.append(stackTraceElement + "\n");
			if (j == 5) {
				break;
			}
		}
		sbException.append("```");
		return sbException.toString();
	}
	return null;
}
 
Example #15
Source Project: ecs-logging-java   Author: elastic   File: EcsEncoder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public byte[] encode(ILoggingEvent event) {
    StringBuilder builder = new StringBuilder();
    EcsJsonSerializer.serializeObjectStart(builder, event.getTimeStamp());
    EcsJsonSerializer.serializeLogLevel(builder, event.getLevel().toString());
    EcsJsonSerializer.serializeFormattedMessage(builder, event.getFormattedMessage());
    serializeMarkers(event, builder);
    EcsJsonSerializer.serializeServiceName(builder, serviceName);
    EcsJsonSerializer.serializeEventDataset(builder, eventDataset);
    EcsJsonSerializer.serializeThreadName(builder, event.getThreadName());
    EcsJsonSerializer.serializeLoggerName(builder, event.getLoggerName());
    serializeAdditionalFields(builder);
    EcsJsonSerializer.serializeMDC(builder, event.getMDCPropertyMap());
    if (includeOrigin) {
        StackTraceElement[] callerData = event.getCallerData();
        if (callerData != null && callerData.length > 0) {
            EcsJsonSerializer.serializeOrigin(builder, callerData[0]);
        }
    }
    IThrowableProxy throwableProxy = event.getThrowableProxy();
    if (throwableProxy instanceof ThrowableProxy) {
        EcsJsonSerializer.serializeException(builder, ((ThrowableProxy) throwableProxy).getThrowable(), stackTraceAsArray);
    } else if (throwableProxy != null) {
        EcsJsonSerializer.serializeException(builder, throwableProxy.getClassName(), throwableProxy.getMessage(), throwableProxyConverter.convert(event), stackTraceAsArray);
    }
    EcsJsonSerializer.serializeObjectEnd(builder);
    // all these allocations kinda hurt
    return builder.toString().getBytes(UTF_8);
}
 
Example #16
Source Project: ns4_frame   Author: newsettle   File: NSThrowableConvert.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected String throwableProxyToString(IThrowableProxy tp) {
    StringBuilder sb = new StringBuilder(BUILDER_CAPACITY);

    recursiveAppend(sb, null, ThrowableProxyUtil.REGULAR_EXCEPTION_INDENT, tp);

    return sb.toString();
}
 
Example #17
Source Project: ns4_frame   Author: newsettle   File: NSThrowableConvert.java    License: Apache License 2.0 5 votes vote down vote up
private void recursiveAppend(StringBuilder sb, String prefix, int indent, IThrowableProxy tp) {
    if(tp == null)
        return;
    subjoinFirstLine(sb, prefix, indent, tp);
    sb.append(CoreConstants.LINE_SEPARATOR);
    subjoinSTEPArray(sb, indent, tp);
    IThrowableProxy[] suppressed = tp.getSuppressed();
    if(suppressed != null) {
        for(IThrowableProxy current : suppressed) {
            recursiveAppend(sb, CoreConstants.SUPPRESSED, indent + ThrowableProxyUtil.SUPPRESSED_EXCEPTION_INDENT, current);
        }
    }
    recursiveAppend(sb, CoreConstants.CAUSED_BY, indent, tp.getCause());
}
 
Example #18
Source Project: ns4_frame   Author: newsettle   File: NSThrowableConvert.java    License: Apache License 2.0 5 votes vote down vote up
private void subjoinFirstLine(StringBuilder buf, String prefix, int indent, IThrowableProxy tp) {
    ThrowableProxyUtil.indent(buf, indent - 1);


    buf.append(LogConstants.PART_SPLIT);
    if (prefix != null) {
        buf.append(prefix);
    }
    subjoinExceptionMessage(buf, tp);
}
 
Example #19
Source Project: ns4_frame   Author: newsettle   File: NSThrowableConvert.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void subjoinSTEPArray(StringBuilder buf, int indent, IThrowableProxy tp) {
    String totalKey = LogKey.getTotalKey();
    StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
    int commonFrames = tp.getCommonFrames();

    boolean unrestrictedPrinting = Integer.MAX_VALUE > stepArray.length;


    int maxIndex = (unrestrictedPrinting) ? stepArray.length : Integer.MAX_VALUE;
    if (commonFrames > 0 && unrestrictedPrinting) {
        maxIndex -= commonFrames;
    }

    for (int i = 0; i < maxIndex; i++) {
        buf.append(totalKey);
        ThrowableProxyUtil.indent(buf, indent);
        buf.append(stepArray[i]);
        extraData(buf, stepArray[i]); // allow other data to be added
        buf.append(CoreConstants.LINE_SEPARATOR);
    }

    if (commonFrames > 0 && unrestrictedPrinting) {
        buf.append(totalKey);
        ThrowableProxyUtil.indent(buf, indent);
        buf.append("... ").append(tp.getCommonFrames()).append(
                " common frames omitted").append(CoreConstants.LINE_SEPARATOR);
    }
}
 
Example #20
Source Project: arcusplatform   Author: arcus-smart-home   File: IrisLayout.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String doLayout(ILoggingEvent event) {
   if (!isJson) {
      return super.doLayout(event);
   }

   JsonObject object = new JsonObject();
   for(Map.Entry<String, String> e: event.getMDCPropertyMap().entrySet()) {
      object.addProperty(e.getKey(), e.getValue());
   }

   object.addProperty("ts", event.getTimeStamp());
   object.addProperty("sev", event.getLevel().toString());
   object.addProperty("host", IrisApplicationInfo.getHostName());
   if (IrisApplicationInfo.getContainerName() != null) {
      object.addProperty("ctn", IrisApplicationInfo.getContainerName());
   }
   object.addProperty("svc", IrisApplicationInfo.getApplicationName());
   object.addProperty("svr", IrisApplicationInfo.getApplicationVersion());
   object.addProperty("thd", event.getThreadName());
   object.addProperty("log", event.getLoggerName());
   object.addProperty("msg", event.getFormattedMessage());

   IThrowableProxy thrw = event.getThrowableProxy();
   if (thrw != null) {
      String stackTrace = converter.convert(event);
      object.addProperty("exc", stackTrace);
   } else {
      object.remove("exc");
   }

   String json = GSON.toJson(object);
   if (isJsonString) {
      json = GSON.toJson(json);
   }

   return json + "\n";
}
 
Example #21
Source Project: arcusplatform   Author: arcus-smart-home   File: IrisLayout.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String doLayout(@Nullable ILoggingEvent event) {
   if (event == null) {
      return "";
   }

   for(Map.Entry<String, String> e: event.getMDCPropertyMap().entrySet()) {
      object.addProperty(e.getKey(), e.getValue());
   }

   object.addProperty("ts", event.getTimeStamp());
   object.addProperty("lvl", event.getLevel().toString());
   object.addProperty("thd", event.getThreadName());
   object.addProperty("log", event.getLoggerName());
   object.addProperty("msg", event.getFormattedMessage());
   object.addProperty("svc", "agent");

   String hubId = IrisHal.getHubIdOrNull();
   if (hubId != null) {
      object.addProperty("hst", hubId);
   }

   String hubVersion = IrisHal.getOperatingSystemVersionOrNull();
   if (hubVersion != null) {
      object.addProperty("svr", hubVersion);
   }

   IThrowableProxy thrw = event.getThrowableProxy();
   if (thrw != null) {
      String stackTrace = converter.convert(event);
      object.addProperty("exc", stackTrace);
   } else {
      object.remove("exc");
   }

   return IrisAgentSotConverter.SOT + GSON.toJson(object);
}
 
Example #22
Source Project: xian   Author: xiancloud   File: LogbackLogEvent.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Throwable getThrowable() {
    Throwable result = null;
    IThrowableProxy throwableProxy = loggingEvent.getThrowableProxy();
    if (null != throwableProxy) {
        if (throwableProxy instanceof ThrowableProxy) {
            result = ((ThrowableProxy) throwableProxy).getThrowable();
        }
    }
    return result;
}
 
Example #23
Source Project: cloudwatch-logback-appender   Author: dibog   File: ExceptionUtil.java    License: Apache License 2.0 5 votes vote down vote up
private  static void appendStackTrace(StringBuilder sb, String prefix, IThrowableProxy aProxy) {

        StackTraceElementProxy[] frames = aProxy.getStackTraceElementProxyArray();
        int commonFrames = aProxy.getCommonFrames();
        for(int i=0, size=frames.length-commonFrames; i<size; ++i) {
            sb.append(prefix+frames[i]+"\n");
        }
        if (commonFrames>0) {
            sb.append(prefix+"... "+commonFrames+" more"+"\n");
        }
    }
 
Example #24
Source Project: cloudwatch-logback-appender   Author: dibog   File: LoggingEventToStringImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String map(ILoggingEvent event) {

    Map<String,Object> values = new HashMap<>();

    values.put("message", event.getFormattedMessage());
    values.put("level", event.getLevel().levelStr);
    values.put("logger-name", event.getLoggerName());
    values.put("thread-name", event.getThreadName());

    Marker marker = event.getMarker();
    if(marker!=null)
        values.put("marker", marker);

    IThrowableProxy exceptionProxy = event.getThrowableProxy();
    if(exceptionProxy!=null) {
        values.put("exception", ExceptionUtil.toString(exceptionProxy));
    }

    // In theory, event.getMDCPropertyMap() should not be null, in practice it can
    if (event.getMDCPropertyMap() != null && !event.getMDCPropertyMap().isEmpty()) {
        values.put("context", event.getMDCPropertyMap());
    }

    try {
        return m.writeValueAsString(values);
    }
    catch(Exception e) {
        return e.getLocalizedMessage();
    }
}
 
Example #25
Source Project: centraldogma   Author: line   File: ExpectedExceptionAppender.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void append(ILoggingEvent eventObject) {
    final IThrowableProxy exception = getException(eventObject);
    for (String exceptionName : exceptionAndMessage.keySet()) {
        if (exception != null && exception.getClassName().endsWith(exceptionName) &&
            containsMessage(exception, exceptionName)) {
            aai.appendLoopOnAppenders(new ExpectedExceptionEventWrapper(eventObject));
            return;
        }
    }
    aai.appendLoopOnAppenders(eventObject);
}
 
Example #26
Source Project: centraldogma   Author: line   File: ExpectedExceptionAppender.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static IThrowableProxy getException(ILoggingEvent event) {
    final IThrowableProxy throwableProxy = event.getThrowableProxy();
    if (throwableProxy != null) {
        final IThrowableProxy cause = throwableProxy.getCause();
        if (cause != null) {
            return cause;
        }
    }
    return null;
}
 
Example #27
Source Project: styx   Author: HotelsDotCom   File: LoggingEventMatcher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void describeMismatchSafely(ILoggingEvent item, Description description) {
    description.appendText(format("loggingEvent(level=%s, message='%s'", item.getLevel(), item.getFormattedMessage()));

    IThrowableProxy throwableProxy = item.getThrowableProxy();

    if (throwableProxy != null) {
        description.appendText(" ");
        describeException(description, throwableProxy.getClassName(), throwableProxy.getMessage());
    }

    description.appendText(")");
}
 
Example #28
Source Project: styx   Author: HotelsDotCom   File: ExceptionConverter.java    License: Apache License 2.0 5 votes vote down vote up
private String getExceptionData(final ILoggingEvent loggingEvent) {
    IThrowableProxy throwableProxy = loggingEvent.getThrowableProxy();
    StackTraceElementProxy loggableStackTraceElement =
            findFirstStackTraceElementForClasses(throwableProxy, readStyxClassesFromProperty())
                    .orElse(getTopStackTraceElement(throwableProxy));

    return Optional.ofNullable(loggableStackTraceElement)
            .map(ExceptionConverter::createExceptionMessage)
            .orElse(NO_MSG);
}
 
Example #29
Source Project: styx   Author: HotelsDotCom   File: ExceptionConverter.java    License: Apache License 2.0 5 votes vote down vote up
private Iterable<IThrowableProxy> collectThrowableProxies(final IThrowableProxy throwableProxy) {
    IThrowableProxy[] throwableProxyArray = new IThrowableProxy[MAXIMUM_ALLOWED_DEPTH];
    IThrowableProxy actualThrowableProxy = throwableProxy;
    for (int i = 0; i < throwableProxyArray.length; i++) {
        if (actualThrowableProxy != null) {
            throwableProxyArray[i] = actualThrowableProxy;
            actualThrowableProxy = actualThrowableProxy.getCause();
        } else {
            break;
        }
    }
    return asList(throwableProxyArray);
}
 
Example #30
Source Project: styx   Author: HotelsDotCom   File: ExceptionConverter.java    License: Apache License 2.0 5 votes vote down vote up
private StackTraceElementProxy getTopStackTraceElement(final IThrowableProxy throwableProxy) {
    StackTraceElementProxy stackTraceLine = null;
    StackTraceElementProxy[] stackTraceElementProxyArray = throwableProxy.getStackTraceElementProxyArray();
    if (stackTraceElementProxyArray != null && stackTraceElementProxyArray.length > 0) {
        stackTraceLine = stackTraceElementProxyArray[0];
    }
    return stackTraceLine;
}