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

The following examples show how to use ch.qos.logback.classic.spi.ThrowableProxy. 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: SpanLogsAppender.java    From java-spring-cloud with 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 #2
Source File: LogbackUtilTest.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: LoggingFilter.java    From NationStatesPlusPlus with 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 #4
Source File: EcsEncoder.java    From ecs-logging-java with 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 #5
Source File: LogbackLoggingConfigurer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    try {
        ThrowableProxy throwableProxy = (ThrowableProxy) event.getThrowableProxy();
        Throwable throwable = throwableProxy == null ? null : throwableProxy.getThrowable();
        String message = event.getFormattedMessage();
        LogLevel level = LogLevelConverter.toGradleLogLevel(event.getLevel(), event.getMarker());
        outputEventListener.onOutput(new LogEvent(event.getTimeStamp(), event.getLoggerName(), level, message, throwable));
    } catch (Throwable t) {
        // fall back to standard out
        t.printStackTrace(defaultStandardOut);
    }
}
 
Example #6
Source File: LogbackLoggingConfigurer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    try {
        ThrowableProxy throwableProxy = (ThrowableProxy) event.getThrowableProxy();
        Throwable throwable = throwableProxy == null ? null : throwableProxy.getThrowable();
        String message = event.getFormattedMessage();
        LogLevel level = LogLevelConverter.toGradleLogLevel(event.getLevel(), event.getMarker());
        outputEventListener.onOutput(new LogEvent(event.getTimeStamp(), event.getLoggerName(), level, message, throwable));
    } catch (Throwable t) {
        // fall back to standard out
        t.printStackTrace(defaultStandardOut);
    }
}
 
Example #7
Source File: LogbackLogEvent.java    From xian with 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 #8
Source File: CloudWatchAppender.java    From cloudwatch-logback-appender with ISC License 5 votes vote down vote up
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;
}
 
Example #9
Source File: ErrorCatcher.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
    String msg = event.getFormattedMessage();
    if (msg == null)
        msg = "null";
    if (event.getMarker() != Markers.NO_ANNOUNCE
            && FlareBot.instance() != null
            && event.getLevel() == Level.ERROR || event.getLevel() == Level.WARN) {
        String finalMsg = msg;
        if (event.getThreadName().startsWith("lava-daemon-pool")) {
            return FilterReply.NEUTRAL;
        }
        EXECUTOR.submit(() -> {
            Throwable throwable = null;
            if (event.getThrowableProxy() != null && event.getThrowableProxy() instanceof ThrowableProxy) {
                throwable = ((ThrowableProxy) event.getThrowableProxy()).getThrowable();
            }
            if (event.getLevel() == Level.WARN) {
                // Warnings should not have a throwable!
                MessageUtils.sendWarningMessage(finalMsg, Constants.getErrorLogChannel());
                return;
            }
            if (throwable != null) {
                if (event.getMarker() == Markers.TAG_DEVELOPER)
                    MessageUtils.sendFatalException(finalMsg, throwable, Constants.getErrorLogChannel());
                else
                    MessageUtils.sendException(finalMsg, throwable, Constants.getErrorLogChannel());
            } else {
                if (event.getMarker() == Markers.TAG_DEVELOPER)
                    MessageUtils.sendFatalErrorMessage(finalMsg, Constants.getErrorLogChannel());
                else
                    MessageUtils.sendErrorMessage(finalMsg, Constants.getErrorLogChannel());
            }
        });
    }
    return FilterReply.NEUTRAL;
}
 
Example #10
Source File: YarnTwillLogHandler.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void onLog(LogEntry logEntry) {

  final LoggingEvent loggingEvent = new LoggingEvent();
  loggingEvent.setTimeStamp(logEntry.getTimestamp());
  loggingEvent.setLoggerName(logEntry.getLoggerName());
  loggingEvent.setLevel(Level.valueOf(logEntry.getLogLevel().name()));
  loggingEvent.setThreadName(logEntry.getThreadName());
  Object [] formatObjects = new Object[] {logEntry.getHost(),
    getSimpleClassName(logEntry.getSourceClassName()),
    logEntry.getSourceMethodName(),
    logEntry.getFileName(),
    logEntry.getLineNumber(),logEntry.getMessage()};
  loggingEvent.setMessage(MESSAGE_FORMAT.get().format(formatObjects));

  // Prints the throwable and stack trace.
  LogThrowable logThrowable = logEntry.getThrowable();
  if (logThrowable != null) {
    loggingEvent.setThrowableProxy(new ThrowableProxy(setThrowable(logThrowable)));
  }

  if (logger instanceof Logger) {
    ((Logger) logger).callAppenders(loggingEvent);
  } else {
    logger.info("Logger is not instance of ch.qos.logback.classic.Logger. Logger event is: {}", loggingEvent);
  }
}
 
Example #11
Source File: LogbackStacktraceConverter.java    From cf-java-logging-support with Apache License 2.0 5 votes vote down vote up
@Override
public String convert(ILoggingEvent event) {
    StringBuilder appendTo = new StringBuilder();
    IThrowableProxy tProxy = event.getThrowableProxy();
    if (tProxy != null && ThrowableProxy.class.isAssignableFrom(tProxy.getClass())) {
        StacktraceConverter.CONVERTER.convert(((ThrowableProxy) tProxy).getThrowable(), appendTo);
        return appendTo.toString();
    }
    return null;
}
 
Example #12
Source File: LogbackLoggingConfigurer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    try {
        ThrowableProxy throwableProxy = (ThrowableProxy) event.getThrowableProxy();
        Throwable throwable = throwableProxy == null ? null : throwableProxy.getThrowable();
        String message = event.getFormattedMessage();
        LogLevel level = LogLevelConverter.toGradleLogLevel(event.getLevel(), event.getMarker());
        outputEventListener.onOutput(new LogEvent(event.getTimeStamp(), event.getLoggerName(), level, message, throwable));
    } catch (Throwable t) {
        // fall back to standard out
        t.printStackTrace(defaultStandardOut);
    }
}
 
Example #13
Source File: LogbackLoggingConfigurer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    try {
        ThrowableProxy throwableProxy = (ThrowableProxy) event.getThrowableProxy();
        Throwable throwable = throwableProxy == null ? null : throwableProxy.getThrowable();
        String message = event.getFormattedMessage();
        LogLevel level = LogLevelConverter.toGradleLogLevel(event.getLevel(), event.getMarker());
        outputEventListener.onOutput(new LogEvent(event.getTimeStamp(), event.getLoggerName(), level, message, throwable));
    } catch (Throwable t) {
        // fall back to standard out
        t.printStackTrace(defaultStandardOut);
    }
}
 
Example #14
Source File: BugsnagAppender.java    From bugsnag-java with MIT License 5 votes vote down vote up
/**
 * Gets the throwable from the log event (if any)
 * @param event The log event
 * @return The throwable (or null)
 */
private Throwable extractThrowable(ILoggingEvent event) {
    IThrowableProxy throwableProxy = event.getThrowableProxy();
    if (throwableProxy instanceof ThrowableProxy) {
        return ((ThrowableProxy) throwableProxy).getThrowable();
    }

    return null;
}
 
Example #15
Source File: ExceptionConverterTest.java    From styx with Apache License 2.0 4 votes vote down vote up
private ILoggingEvent newErrorLoggingEvent(Throwable throwable) {
    LoggingEvent loggingEvent = new LoggingEvent();
    loggingEvent.setLevel(Level.ERROR);
    loggingEvent.setThrowableProxy(new ThrowableProxy(throwable));
    return loggingEvent;
}