Java Code Examples for org.apache.logging.log4j.core.util.Throwables#getRootCause()

The following examples show how to use org.apache.logging.log4j.core.util.Throwables#getRootCause() . 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 File: ExceptionRootCauseResolver.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
EventResolver createClassNameResolver() {
    return (final LogEvent logEvent, final JsonWriter jsonWriter) -> {
        final Throwable exception = logEvent.getThrown();
        if (exception == null) {
            jsonWriter.writeNull();
        } else {
            final Throwable rootCause = Throwables.getRootCause(exception);
            final String rootCauseClassName = rootCause.getClass().getCanonicalName();
            jsonWriter.writeString(rootCauseClassName);
        }
    };
}
 
Example 2
Source File: ExceptionRootCauseResolver.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
EventResolver createMessageResolver(final EventResolverContext context) {
    return (final LogEvent logEvent, final JsonWriter jsonWriter) -> {
        final Throwable exception = logEvent.getThrown();
        if (exception == null) {
            jsonWriter.writeNull();
        } else {
            final Throwable rootCause = Throwables.getRootCause(exception);
            final String rootCauseMessage = rootCause.getMessage();
            jsonWriter.writeString(rootCauseMessage);
        }
    };
}
 
Example 3
Source File: ExceptionRootCauseResolver.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
EventResolver createStackTraceStringResolver(final EventResolverContext context) {
    final StackTraceStringResolver stackTraceStringResolver =
            new StackTraceStringResolver(context);
    return (final LogEvent logEvent, final JsonWriter jsonWriter) -> {
        final Throwable exception = logEvent.getThrown();
        if (exception == null) {
            jsonWriter.writeNull();
        } else {
            final Throwable rootCause = Throwables.getRootCause(exception);
            stackTraceStringResolver.resolve(rootCause, jsonWriter);
        }
    };
}
 
Example 4
Source File: ExceptionRootCauseResolver.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
EventResolver createStackTraceObjectResolver(EventResolverContext context) {
    return (final LogEvent logEvent, final JsonWriter jsonWriter) -> {
        final Throwable exception = logEvent.getThrown();
        if (exception == null) {
            jsonWriter.writeNull();
        } else {
            final Throwable rootCause = Throwables.getRootCause(exception);
            context.getStackTraceObjectResolver().resolve(rootCause, jsonWriter);
        }
    };
}