本文整理汇总了Java中ch.qos.logback.classic.spi.ThrowableProxy类的典型用法代码示例。如果您正苦于以下问题:Java ThrowableProxy类的具体用法?Java ThrowableProxy怎么用?Java ThrowableProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThrowableProxy类属于ch.qos.logback.classic.spi包,在下文中一共展示了ThrowableProxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFromThrowableProxy
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
public static AbstractLoggingException getFromThrowableProxy(ThrowableProxy proxy) {
if (proxy != null) {
Throwable eventException = proxy.getThrowable();
if (eventException instanceof AbstractLoggingException) {
return (AbstractLoggingException) eventException;
} else if (eventException.getCause() instanceof AbstractLoggingException) {
// for spring boot projects there's a generic exception wrapper
// let's try to cast the cause instead
return (AbstractLoggingException) eventException.getCause();
} else {
triggerBadImplementationLog(eventException);
return null;
}
}
return null;
}
示例2: appendStackTrace
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
private void appendStackTrace(StringBuilder log, ThrowableProxy proxy) {
if (proxy != null) {
Stream<StackTraceElementProxy> trace = Arrays.stream(proxy.getStackTraceElementProxyArray());
trace.forEach(step -> {
String string = step.toString();
log.append(CoreConstants.TAB).append(string);
ThrowableProxyUtil.subjoinPackagingData(log, step);
log.append(CoreConstants.LINE_SEPARATOR);
});
trace.close();
}
}
示例3: loopCauses
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
private void loopCauses(StringBuilder log, ThrowableProxy parentProxy, int depth) {
ThrowableProxy cause = (ThrowableProxy) parentProxy.getCause();
if (cause != null) {
log.append(String.format(
"Caused by: %s: %s",
cause.getThrowable().getClass().getCanonicalName(),
cause.getThrowable().getMessage()
));
log.append(CoreConstants.LINE_SEPARATOR);
}
appendStackTrace(log, cause);
if (cause != null && depth < STACKTRACE_DEPTH) {
loopCauses(log, cause, depth + 1);
}
}
示例4: decide
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Override
public FilterReply decide(ILoggingEvent event) {
if (event.getFormattedMessage().contains("Received 404 error, please notify the developer and include the URL ("))
return FilterReply.DENY;
if (event.getMarker() != Markers.NO_ANNOUNCE && Launcher.getInstance().getClient().isReady() && event.getLevel() == Level.ERROR) {
String msg = event.getFormattedMessage();
if (event.getThrowableProxy() != null && event.getThrowableProxy() instanceof ThrowableProxy) {
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
Throwable throwable = ((ThrowableProxy) event.getThrowableProxy()).getThrowable();
if (throwable != null) {
msg += ' ';
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
msg += sw.toString();
pw.close();
}
}
Messages.send(msg, Launcher.getInstance().getClient().getChannelByID("233632081110892546"));
}
return FilterReply.NEUTRAL;
}
示例5: decide
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Override
public FilterReply decide(ILoggingEvent event) {
String msg = event.getFormattedMessage();
if (msg.startsWith("Received 40")) {
return FilterReply.DENY;
}
if (msg.startsWith("Attempt to send message on closed")) {
return FilterReply.DENY;
}
if (event.getMarker() != Markers.NO_ANNOUNCE
&& FlareBot.getInstance().getClient() != null
&& FlareBot.getInstance().getClient().isReady()
&& event.getLevel() == Level.ERROR) {
EXECUTOR.submit(() -> {
Throwable throwable = null;
if (event.getThrowableProxy() != null && event.getThrowableProxy() instanceof ThrowableProxy) {
throwable = ((ThrowableProxy) event.getThrowableProxy()).getThrowable();
}
if (throwable != null) {
MessageUtils.sendException(msg, throwable, FlareBot.getInstance().getUpdateChannel());
} else MessageUtils.sendMessage(msg, FlareBot.getInstance().getUpdateChannel());
});
}
return FilterReply.NEUTRAL;
}
示例6: testAddException
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@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());
}
示例7: testEncodeArrayWithException
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Test
public void testEncodeArrayWithException() throws Exception {
final LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
event.setMarker(StenoMarker.ARRAY_MARKER);
event.setMessage("logEvent");
event.setLoggerContextRemoteView(_context.getLoggerContextRemoteView());
event.setTimeStamp(0);
event.setThrowableProxy(new ThrowableProxy(new NullPointerException("npe!")));
final Object[] argArray = new Object[2];
argArray[0] = new String[]{};
argArray[1] = new Object[]{};
event.setArgumentArray(argArray);
// CHECKSTYLE.OFF: IllegalInstantiation - This is valid case.
final String logOutput = new String(_encoder.encode(event), _encoder.getCharset());
// CHECKSTYLE.ON: IllegalInstantiation
assertOutput("StenoEncoderTest.testEncodeArrayWithException.json", logOutput);
assertMatchesJsonSchema(logOutput);
}
示例8: testEncodeArrayWithCausedException
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Test
public void testEncodeArrayWithCausedException() throws Exception {
final LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
event.setMarker(StenoMarker.ARRAY_MARKER);
event.setMessage("logEvent");
event.setLoggerContextRemoteView(_context.getLoggerContextRemoteView());
event.setTimeStamp(0);
event.setThrowableProxy(new ThrowableProxy(new UnsupportedOperationException("uoe!", new NullPointerException("npe!"))));
final Object[] argArray = new Object[2];
argArray[0] = new String[]{};
argArray[1] = new Object[]{};
event.setArgumentArray(argArray);
// CHECKSTYLE.OFF: IllegalInstantiation - This is valid case.
final String logOutput = new String(_encoder.encode(event), _encoder.getCharset());
// CHECKSTYLE.ON: IllegalInstantiation
assertOutput("StenoEncoderTest.testEncodeArrayWithCausedException.json", logOutput);
assertMatchesJsonSchema(logOutput);
}
示例9: testEncodeArrayWithSuppressedException
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Test
public void testEncodeArrayWithSuppressedException() throws Exception {
final LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
event.setMarker(StenoMarker.ARRAY_MARKER);
event.setMessage("logEvent");
event.setLoggerContextRemoteView(_context.getLoggerContextRemoteView());
event.setTimeStamp(0);
final Throwable throwable = new NullPointerException("npe!");
throwable.addSuppressed(new UnsupportedOperationException("uoe!"));
event.setThrowableProxy(new ThrowableProxy(throwable));
final Object[] argArray = new Object[2];
argArray[0] = new String[]{};
argArray[1] = new Object[]{};
event.setArgumentArray(argArray);
// CHECKSTYLE.OFF: IllegalInstantiation - This is valid case.
// CHECKSTYLE.OFF: IllegalInstantiation - This is valid case.
final String logOutput = new String(_encoder.encode(event), _encoder.getCharset());
// CHECKSTYLE.ON: IllegalInstantiation
// CHECKSTYLE.ON: IllegalInstantiation
assertOutput("StenoEncoderTest.testEncodeArrayWithSuppressedException.json", logOutput);
assertMatchesJsonSchema(logOutput);
}
示例10: testEncodeArrayWithNullSuppressedException
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Test
@SuppressFBWarnings(value = "SIC_INNER_SHOULD_BE_STATIC_ANON")
public void testEncodeArrayWithNullSuppressedException() throws Exception {
final LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
event.setMarker(StenoMarker.ARRAY_MARKER);
event.setMessage("logEvent");
event.setLoggerContextRemoteView(_context.getLoggerContextRemoteView());
event.setTimeStamp(0);
event.setThrowableProxy(new ThrowableProxy(new NullPointerException("npe!")) {
@Override
@SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS")
public IThrowableProxy[] getSuppressed() {
return null;
}
});
final Object[] argArray = new Object[2];
argArray[0] = new String[]{};
argArray[1] = new Object[]{};
event.setArgumentArray(argArray);
// CHECKSTYLE.OFF: IllegalInstantiation - This is valid case.
final String logOutput = new String(_encoder.encode(event), _encoder.getCharset());
// CHECKSTYLE.ON: IllegalInstantiation
assertOutput("StenoEncoderTest.testEncodeArrayWithNullSuppressedException.json", logOutput);
assertMatchesJsonSchema(logOutput);
}
示例11: append
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Override
protected void append(ILoggingEvent event) {
final IThrowableProxy throwableProxy = event.getThrowableProxy();
final Map<String, String> mdc = event.getMDCPropertyMap();
if ((throwableProxy != null) && (throwableProxy instanceof ThrowableProxy)) {
ThrowableProxy proxy = (ThrowableProxy) throwableProxy;
if (proxy.getThrowable() != null) {
Map<String, String> params = new HashMap<>(mdc);
if (!mdc.containsKey(MESSAGE_PARAM)) {
params.put(MESSAGE_PARAM, event.getFormattedMessage());
}
noticeError(proxy.getThrowable(), params);
return;
}
}
noticeError(event.getFormattedMessage(), mdc);
}
示例12: decide
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@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;
}
示例13: makeEvent
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
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;
}
示例14: matches
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Override
public boolean matches(Object item) {
if (item instanceof ThrowableProxy) {
return expectedException.matches(((ThrowableProxy) item).getThrowable());
}
return false;
}
示例15: match_when_ThrowableProxy_contains_exception
import ch.qos.logback.classic.spi.ThrowableProxy; //导入依赖的package包/类
@Test
public void match_when_ThrowableProxy_contains_exception() {
ExpectedExceptionMatcher expectedExceptionMatcher = new ExpectedExceptionMatcher(isA(RuntimeException.class));
boolean matches = expectedExceptionMatcher.matches(new ThrowableProxy(new RuntimeException()));
assertThat(matches).isTrue();
}