public String fullDump(ILoggingEvent evt) { try { IThrowableProxy proxy = evt.getThrowableProxy(); if(proxy == null) return null; StringBuilder builder = new StringBuilder(); for (StackTraceElementProxy step : proxy .getStackTraceElementProxyArray()) { String string = step.toString(); builder.append(CoreConstants.TAB).append(string); ThrowableProxyUtil.subjoinPackagingData(builder, step); builder.append(CoreConstants.LINE_SEPARATOR); } return builder.toString(); } catch(Exception e) { addError("exception trying to log exception", e); return "exception parsing exception"; } }
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(); } }
protected void recursiveAppendRootCauseFirst(StringBuilder sb, String prefix, int indent, IThrowableProxy tp) { if (tp.getCause() != null) { recursiveAppendRootCauseFirst(sb, prefix, indent, tp.getCause()); prefix = null; // to avoid adding it more than once } ThrowableProxyUtil.indent(sb, indent - 1); if (prefix != null) { sb.append(prefix); } ThrowableProxyUtil.subjoinFirstLineRootCauseFirst(sb, tp); sb.append(CoreConstants.LINE_SEPARATOR); subjoinSTEPArray(sb, indent, tp); IThrowableProxy[] suppressed = tp.getSuppressed(); if(suppressed != null) { for(IThrowableProxy current : suppressed) { recursiveAppendRootCauseFirst(sb, CoreConstants.SUPPRESSED, indent + ThrowableProxyUtil.SUPPRESSED_EXCEPTION_INDENT, current); } } }
@Override protected void append(ILoggingEvent rawData) { final Map<String, Object> data = new HashMap<String, Object>(); data.put("message", rawData.getFormattedMessage()); data.put("logger", rawData.getLoggerName()); data.put("thread", rawData.getThreadName()); data.put("level", rawData.getLevel()); if (rawData.getMarker() != null) { data.put("marker", rawData.getMarker()); } if (rawData.hasCallerData()) { data.put("caller", new CallerDataConverter().convert(rawData)); } if (rawData.getThrowableProxy() != null) { data.put("throwable", ThrowableProxyUtil.asString(rawData.getThrowableProxy())); } for (Entry<String, String> entry : rawData.getMDCPropertyMap().entrySet()) { data.put(entry.getKey(), entry.getValue()); } fluentLogger.log(label, data, rawData.getTimeStamp() / 1000); }
private void errorAppender(StringBuilder sb, ILoggingEvent iLoggingEvent) { if ( iLoggingEvent.getThrowableProxy() != null ) { appendKeyValueAndEscape(sb, ERROR.toString(), ThrowableProxyUtil.asString(iLoggingEvent.getThrowableProxy())); } }
private String fullDump(StackTraceElementProxy[] stackTraceElementProxyArray) { StringBuilder builder = new StringBuilder(); for (StackTraceElementProxy step : stackTraceElementProxyArray) { builder.append(CoreConstants.LINE_SEPARATOR); String string = step.toString(); builder.append(CoreConstants.TAB).append(string); ThrowableProxyUtil.subjoinPackagingData(builder, step); } return builder.toString(); }
private String dump(IThrowableProxy throwableProxy) { StringBuilder builder = new StringBuilder(); builder.append(throwableProxy.getClassName()).append(": ").append(throwableProxy.getMessage()).append(CoreConstants.LINE_SEPARATOR); for (StackTraceElementProxy step : throwableProxy.getStackTraceElementProxyArray()) { String string = step.toString(); builder.append(CoreConstants.TAB).append(string); ThrowableProxyUtil.subjoinPackagingData(builder, step); builder.append(CoreConstants.LINE_SEPARATOR); } return builder.toString(); }
@Override protected void append (ILoggingEvent event) { if (MMDBot.state.isReady()) { final Level level = event.getLevel(); final EmbedBuilder embed = new EmbedBuilder(); if (level == Level.DEBUG && !event.getLoggerName().equalsIgnoreCase("MMDBot")) { return; } if (level == Level.TRACE && event.getLoggerName().equalsIgnoreCase("sx.blah.discord.Discord4J")) { return; } embed.withTitle(level.levelStr); embed.withColor(level == Level.DEBUG ? DEBUG : level == Level.ERROR || level == Level.TRACE ? ERROR : level == Level.INFO ? INFO : level == Level.WARN ? WARN : UNKNOWN); embed.withDesc(event.getFormattedMessage() + " - Logger: " + event.getLoggerName()); if (event.getThrowableProxy() != null) { embed.appendDesc(Utilities.SEPERATOR + ThrowableProxyUtil.asString(event.getThrowableProxy())); } Utilities.sendMessage(MMDBot.state.getConsoleChannel(), embed.build()); } }
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()); }
private void subjoinFirstLine(StringBuilder buf, String prefix, int indent, IThrowableProxy tp) { ThrowableProxyUtil.indent(buf, indent - 1); if (prefix != null) { buf.append(prefix); } subjoinExceptionMessage(buf, tp); }
protected void subjoinSTEPArray(StringBuilder buf, int indent, IThrowableProxy tp) { StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray(); int commonFrames = tp.getCommonFrames(); boolean unrestrictedPrinting = lengthOption > stepArray.length; int maxIndex = (unrestrictedPrinting) ? stepArray.length : lengthOption; if (commonFrames > 0 && unrestrictedPrinting) { maxIndex -= commonFrames; } int ignoredCount = 0; for (int i = 0; i < maxIndex; i++) { StackTraceElementProxy element = stepArray[i]; if (!isIgnoredStackTraceLine(element.toString())) { ThrowableProxyUtil.indent(buf, indent); printStackLine(buf, ignoredCount, element); ignoredCount = 0; buf.append(CoreConstants.LINE_SEPARATOR); } else { ++ignoredCount; if (maxIndex < stepArray.length) { ++maxIndex; } } } if (ignoredCount > 0) { printIgnoredCount(buf, ignoredCount); buf.append(CoreConstants.LINE_SEPARATOR); } if (commonFrames > 0 && unrestrictedPrinting) { ThrowableProxyUtil.indent(buf, indent); buf.append("... ").append(tp.getCommonFrames()).append( " common frames omitted").append(CoreConstants.LINE_SEPARATOR); } }
/** * Dump the events passed as argument into the file named targetFile. * * @param eventArray * @param targetFile * @throws IOException */ public static void dump(ILoggingEvent[] eventArray, String targetFile) throws IOException { FileWriter fw = new FileWriter(targetFile); for (ILoggingEvent e : eventArray) { fw.write(e.toString()); fw.append(CoreConstants.LINE_SEPARATOR); if (e.getThrowableProxy() != null) { IThrowableProxy tp = e.getThrowableProxy(); fw.write(ThrowableProxyUtil.asString(tp)); } } fw.flush(); fw.close(); }
@Override protected String throwableProxyToString(IThrowableProxy tp) { StringBuilder buf = new StringBuilder(BUILDER_CAPACITY); recursiveAppendRootCauseFirst(buf, null, ThrowableProxyUtil.REGULAR_EXCEPTION_INDENT, tp); return buf.toString(); }
@Override protected void extraData(StringBuilder builder, StackTraceElementProxy step) { ThrowableProxyUtil.subjoinPackagingData(builder, step); }
@Override protected void extraData(StringBuilder builder, StackTraceElementProxy step) { if (step != null) { ThrowableProxyUtil.subjoinPackagingData(builder, step); } }
@Override protected void append(ILoggingEvent event) { if (Objects.isNull(logViewer)) return; String message = event.getFormattedMessage(); String level = event.getLevel().toString(); if (Objects.isNull(message)) { return; } if (event.getLevel() == Level.ERROR) { logShowHider.getStyleClass().add("red-label"); } final String finalMessage = message; threadService.buff("logMessager").schedule(() -> { threadService.runActionLater(() -> { logShortMessage.setText(finalMessage); }); }, 1, TimeUnit.SECONDS); IThrowableProxy tp = event.getThrowableProxy(); if (Objects.nonNull(tp) && event.getLevel() == Level.ERROR) { String tpMessage = ThrowableProxyUtil.asString(tp); message += "\n" + tpMessage; } if (!message.isEmpty()) { MyLog myLog = new MyLog(level, message); buffer.add(myLog); } threadService.buff("logAppender").schedule(() -> { final List<MyLog> clone = new LinkedList<>(buffer); buffer.clear(); threadService.runActionLater(() -> { logList.addAll(clone); }); }, 2, TimeUnit.SECONDS); }
protected String throwableProxyToString(IThrowableProxy tp) { StringBuilder sb = new StringBuilder(BUILDER_CAPACITY); recursiveAppend(sb, null, ThrowableProxyUtil.REGULAR_EXCEPTION_INDENT, tp); return sb.toString(); }
protected String getThrowableString( Throwable throwable ) { if( throwable == null ) return null; ThrowableProxy throwableProxy = new ThrowableProxy( throwable ); throwableProxy.calculatePackagingData(); return ThrowableProxyUtil.asString( throwableProxy ); }
@Override public String doLayout( ILoggingEvent event ) { if( ! isStarted() ) { return CoreConstants.EMPTY_STRING; } String header = writeLoopOnConverters( event ); header = ( " ".equals(header) ) ? "" : header + " "; String message = event.getFormattedMessage(); if( event.getThrowableProxy() != null ) { message += "\n" + ThrowableProxyUtil.asString( event.getThrowableProxy() ); } StringBuilder sb = new StringBuilder( 128 ); StringBuilder buffer = new StringBuilder(); for( char c : message.toCharArray() ) { switch( c ) { case '\r' : continue; case '\n' : sb.append( header ).append( buffer ).append( CoreConstants.LINE_SEPARATOR ); buffer = new StringBuilder(); break; default : buffer.append( c ); } } sb.append( header ).append( buffer ).append( CoreConstants.LINE_SEPARATOR ); return sb.toString(); }