Java Code Examples for org.slf4j.helpers.FormattingTuple#getThrowable()
The following examples show how to use
org.slf4j.helpers.FormattingTuple#getThrowable() .
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: RntbdReporter.java From azure-cosmosdb-java with MIT License | 6 votes |
private static void doReportIssue(Logger logger, Object subject, String format, Object[] arguments) { FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments); StackTraceElement[] stackTrace = new Exception().getStackTrace(); Throwable throwable = formattingTuple.getThrowable(); if (throwable == null) { logger.error("Report this {} issue to ensure it is addressed:\n[{}]\n[{}]\n[{}]", codeSource, subject, stackTrace[2], formattingTuple.getMessage() ); } else { logger.error("Report this {} issue to ensure it is addressed:\n[{}]\n[{}]\n[{}{}]", codeSource, subject, stackTrace[2], formattingTuple.getMessage(), ExceptionUtils.getStackTrace(throwable) ); } }
Example 2
Source File: JDK14LoggerAdapter.java From HttpSessionReplacer with MIT License | 6 votes |
private LogRecord eventToRecord(LoggingEvent event, Level julLevel) { String format = event.getMessage(); Object[] arguments = event.getArgumentArray(); FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); if (ft.getThrowable() != null && event.getThrowable() != null) { throw new IllegalArgumentException("both last element in argument array and last argument are of type Throwable"); } Throwable t = event.getThrowable(); if (ft.getThrowable() != null) { t = ft.getThrowable(); throw new IllegalStateException("fix above code"); } LogRecord record = new LogRecord(julLevel, ft.getMessage()); record.setLoggerName(event.getLoggerName()); record.setMillis(event.getTimeStamp()); record.setSourceClassName(EventConstants.NA_SUBST); record.setSourceMethodName(EventConstants.NA_SUBST); record.setThrown(t); return record; }
Example 3
Source File: MessageValueSupplier.java From slf4android with MIT License | 6 votes |
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override public void append(LogRecord record, StringBuilder builder) { FormattingTuple formattingTuple = MessageFormatter.arrayFormat(record.getMessage(), record.getParameters()); String message = formattingTuple.getMessage(); Throwable throwable = formattingTuple.getThrowable(); if (throwable != null) { StringWriter writer = new StringWriter(100); PrintWriter printWriter = new PrintWriter(writer); throwable.printStackTrace(printWriter); printWriter.flush(); printWriter.close(); writer.flush(); message += " " + writer.toString(); } builder.append(message); }
Example 4
Source File: JavaLoggerFacade.java From eclair with Apache License 2.0 | 5 votes |
@Override public void log(LogLevel level, String format, Object... arguments) { FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments); String message = formattingTuple.getMessage(); Throwable throwable = formattingTuple.getThrowable(); logger.log(LEVELS.get(level), message, throwable); }
Example 5
Source File: MessageLogger.java From xltsearch with Apache License 2.0 | 5 votes |
private void add(Message.Level level, FormattingTuple tp) { if (tp.getThrowable() == null) { add(level, tp.getMessage()); } else { add(level, tp.getMessage(), tp.getThrowable()); } }
Example 6
Source File: LoggerForMavenLog.java From deadcode4j with Apache License 2.0 | 5 votes |
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") private void doInfo(FormattingTuple tuple) { if (tuple.getThrowable() == null) { log.info(tuple.getMessage()); } else { log.info(tuple.getMessage(), tuple.getThrowable()); } }
Example 7
Source File: LoggerForMavenLog.java From deadcode4j with Apache License 2.0 | 5 votes |
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") private void doWarn(FormattingTuple tuple) { if (tuple.getThrowable() == null) { log.warn(tuple.getMessage()); } else { log.warn(tuple.getMessage(), tuple.getThrowable()); } }
Example 8
Source File: LoggerForMavenLog.java From deadcode4j with Apache License 2.0 | 5 votes |
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") private void doError(FormattingTuple tuple) { if (tuple.getThrowable() == null) { log.error(tuple.getMessage()); } else { log.error(tuple.getMessage(), tuple.getThrowable()); } }
Example 9
Source File: DefaultLogAdapter.java From catnip with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void log(@Nonnull final Level level, @Nonnull final String message, @Nullable final Object... objects) { //noinspection OptionalGetWithoutIsPresent final Class<?> caller = stackWalker.walk(s -> s.skip(2).findFirst()).get().getDeclaringClass(); final Logger logger = LoggerFactory.getLogger(caller); final FormattingTuple tuple = MessageFormatter.arrayFormat(message, objects); final String formatted = tuple.getMessage(); if(logger != null) { switch(level) { case TRACE: { logger.trace(formatted); if(tuple.getThrowable() != null) { logger.trace("Stacktrace: ", tuple.getThrowable()); } break; } case DEBUG: { logger.debug(formatted); if(tuple.getThrowable() != null) { logger.debug("Stacktrace: ", tuple.getThrowable()); } break; } case INFO: { logger.info(formatted); if(tuple.getThrowable() != null) { logger.info("Stacktrace: ", tuple.getThrowable()); } break; } case WARN: { logger.warn(formatted); if(tuple.getThrowable() != null) { logger.warn("Stacktrace: ", tuple.getThrowable()); } break; } case ERROR: { logger.error(formatted); if(tuple.getThrowable() != null) { logger.error("Stacktrace: ", tuple.getThrowable()); } break; } } } }
Example 10
Source File: DolphinLogger.java From dolphin-platform with Apache License 2.0 | 4 votes |
private void log(final Level level, final Marker marker, final String msg, final Throwable throwable, final Object... arguments) { Objects.requireNonNull(level); if (DolphinLoggerUtils.isLevelEnabled(this.level, level)) { final List<String> tempMarkers = new ArrayList<>(); if(marker != null) { tempMarkers.addAll(convert(marker)); } final List<String> currentMarkers = new ArrayList<>(); currentMarkers.addAll(addMarkers(tempMarkers)); currentMarkers.addAll(loggerFactory.getMarkers()); try { final LogMessage logMessage = new LogMessage(); logMessage.setLoggerName(name); logMessage.setLevel(level); logMessage.setMessage(msg); logMessage.setTimestamp(ZonedDateTime.now()); logMessage.setThreadName(Thread.currentThread().getName()); final Map<String, String> context = new HashMap<>(); ContextManagerImpl.getInstance().getGlobalContexts().forEach(c -> context.put(c.getType(), c.getValue())); ContextManagerImpl.getInstance().getThreadContexts().forEach(c -> context.put(c.getType(), c.getValue())); logMessage.setContext(Collections.unmodifiableMap(context)); logMessage.setMarker(currentMarkers); if (throwable != null) { logMessage.setThrowable(throwable); } if (arguments != null && arguments.length > 0) { final FormattingTuple tp = MessageFormatter.arrayFormat(msg, arguments); logMessage.setMessage(tp.getMessage()); if(logMessage.getThrowable() == null && tp.getThrowable() != null) { logMessage.setThrowable(tp.getThrowable()); } } loggerFactory.addToCache(logMessage); for(DolphinLoggerBridge bridge : bridges) { try { bridge.log(logMessage); } catch (Exception e) { System.err.println("Error in Logger: " + e.getMessage()); } } } finally { removeMarkers(tempMarkers); } } }