ch.qos.logback.classic.spi.ThrowableProxyUtil Java Examples
The following examples show how to use
ch.qos.logback.classic.spi.ThrowableProxyUtil.
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: DingTalkAppender.java From jframework with Apache License 2.0 | 6 votes |
private String transformStackTrace(ILoggingEvent event) { String exception = ""; IThrowableProxy throwableProxy = event.getThrowableProxy(); if (throwableProxy != null) { exception = ThrowableProxyUtil.asString(throwableProxy); } StackTraceElement[] callerData = event.getCallerData(); StackTraceElement stackTraceElement = callerData[0]; String time = DEFAULT_DATE_FORMAT.format(new Date(event.getTimeStamp())); String threadName = event.getThreadName(); String level = event.getLevel().toString(); String logger = event.getLoggerName(); String msg = event.getFormattedMessage(); String className = stackTraceElement.getClassName(); String method = stackTraceElement.getMethodName(); int lineNumber = stackTraceElement.getLineNumber(); return String.format(FORMAT_MESSAGE, time, threadName, level, logger, className, method, lineNumber, exception, msg); }
Example #2
Source File: UKeFuAppender.java From youkefu with Apache License 2.0 | 5 votes |
@Override public void append(ILoggingEvent event) { super.append(event); try { if(UKDataContext.getContext()!=null) { Log log = new Log(UKDataContext.SYSTEM_ORGI , null , event.getFormattedMessage() , event.getLevel().toString() , event.getThreadName()); log.setClazz(event.getLoggerName()) ; if(event.getFormattedMessage()!=null && event.getFormattedMessage().length() < 255){ log.setMemo(event.getFormattedMessage()); }else{ log.setMemo(event.getFormattedMessage().substring(0 ,255)); } if(event.getThrowableProxy()!=null){ log.setMsg(ThrowableProxyUtil.asString(event.getThrowableProxy())); } log.setMethod(event.getThreadName()); log.setLogtype(event.getLevel().toString().equals(Level.ERROR.toString()) ? "1" : "0") ; log.setLogtime(String.valueOf(UKTools.dateFormate.format(new Date()))) ; /** * 临时缓存 */ UKDataContext.tempLogQueue.add(log) ; } } catch (Throwable sqle) { sqle.printStackTrace(); } }
Example #3
Source File: NSThrowableConvert.java From ns4_frame with Apache License 2.0 | 5 votes |
@Override protected String throwableProxyToString(IThrowableProxy tp) { StringBuilder sb = new StringBuilder(BUILDER_CAPACITY); recursiveAppend(sb, null, ThrowableProxyUtil.REGULAR_EXCEPTION_INDENT, tp); return sb.toString(); }
Example #4
Source File: NSThrowableConvert.java From ns4_frame with Apache License 2.0 | 5 votes |
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()); }
Example #5
Source File: NSThrowableConvert.java From ns4_frame with Apache License 2.0 | 5 votes |
private void subjoinFirstLine(StringBuilder buf, String prefix, int indent, IThrowableProxy tp) { ThrowableProxyUtil.indent(buf, indent - 1); buf.append(LogConstants.PART_SPLIT); if (prefix != null) { buf.append(prefix); } subjoinExceptionMessage(buf, tp); }
Example #6
Source File: NSThrowableConvert.java From ns4_frame with Apache License 2.0 | 5 votes |
@Override public void subjoinSTEPArray(StringBuilder buf, int indent, IThrowableProxy tp) { String totalKey = LogKey.getTotalKey(); StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray(); int commonFrames = tp.getCommonFrames(); boolean unrestrictedPrinting = Integer.MAX_VALUE > stepArray.length; int maxIndex = (unrestrictedPrinting) ? stepArray.length : Integer.MAX_VALUE; if (commonFrames > 0 && unrestrictedPrinting) { maxIndex -= commonFrames; } for (int i = 0; i < maxIndex; i++) { buf.append(totalKey); ThrowableProxyUtil.indent(buf, indent); buf.append(stepArray[i]); extraData(buf, stepArray[i]); // allow other data to be added buf.append(CoreConstants.LINE_SEPARATOR); } if (commonFrames > 0 && unrestrictedPrinting) { buf.append(totalKey); ThrowableProxyUtil.indent(buf, indent); buf.append("... ").append(tp.getCommonFrames()).append( " common frames omitted").append(CoreConstants.LINE_SEPARATOR); } }
Example #7
Source File: LoghubAppender.java From aliyun-log-logback-appender with Apache License 2.0 | 5 votes |
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(); }
Example #8
Source File: CloudwatchLogsLogbackAppender.java From cloudwatchlogs-java-appender with Apache License 2.0 | 5 votes |
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(); }
Example #9
Source File: Cli.java From bazel-tools with Apache License 2.0 | 4 votes |
@Override protected void append(final ILoggingEvent eventObject) { final Level level = eventObject.getLevel(); final Chalk prefix; switch (level.toInt()) { case Level.ERROR_INT: prefix = ERROR_CHALK; break; case Level.WARN_INT: prefix = WARN_CHALK; break; case Level.INFO_INT: prefix = INFO_CHALK; break; case Level.DEBUG_INT: if (!verbose()) { return; } prefix = DEBUG_CHALK; break; case Level.TRACE_INT: if (!verbose()) { return; } prefix = TRACE_CHALK; break; case Level.OFF_INT: case Level.ALL_INT: default: throw new IllegalArgumentException("Unexpected log level " + level); } System.err.printf( Locale.ROOT, "%s %s: %s%n", toolChalk(), prefix, ansi().render(eventObject.getFormattedMessage())); final IThrowableProxy throwableProxy = eventObject.getThrowableProxy(); if (throwableProxy != null) { for (final String line : Splitter.on('\n') .omitEmptyStrings() .split(ThrowableProxyUtil.asString(throwableProxy))) { System.err.printf(Locale.ROOT, "%s %s: %s%n", toolChalk(), prefix, line); } } }
Example #10
Source File: PrefixedExtendedThrowableProxyConverter.java From bither-desktop-java with Apache License 2.0 | 4 votes |
@Override protected void extraData(StringBuilder builder, StackTraceElementProxy step) { if (step != null) { ThrowableProxyUtil.subjoinPackagingData(builder, step); } }
Example #11
Source File: PrefixedExtendedThrowableProxyConverter.java From bither-desktop-java with Apache License 2.0 | 4 votes |
@Override protected void extraData(StringBuilder builder, StackTraceElementProxy step) { if (step != null) { ThrowableProxyUtil.subjoinPackagingData(builder, step); } }
Example #12
Source File: TableViewLogAppender.java From AsciidocFX with Apache License 2.0 | 4 votes |
@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) { ObservableList<String> styleClass = logShowHider.getStyleClass(); if (!styleClass.contains("red-label")) { styleClass.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); }
Example #13
Source File: JSONEventLayout.java From logback-redis-appender with Apache License 2.0 | 4 votes |
/** * Formats a {@link ILoggingEvent} in conformity with the log4j.dtd. */ public synchronized String doLayout(ILoggingEvent event) { // Reset working buffer. If the buffer is too large, then we need a new // one in order to avoid the penalty of creating a large array. if (buf.capacity() > UPPER_LIMIT) { buf = new StringBuilder(DEFAULT_SIZE); } else { buf.setLength(0); } Map<String, String> mdc = event.getMDCPropertyMap(); buf.append("{"); appendKeyValue(buf, "source", source, mdc); buf.append(COMMA); appendKeyValue(buf, "host", sourceHost, mdc); buf.append(COMMA); appendKeyValue(buf, "path", sourcePath, mdc); buf.append(COMMA); appendKeyValue(buf, "type", type, mdc); buf.append(COMMA); appendKeyValue(buf, "tags", tags, mdc); buf.append(COMMA); appendKeyValue(buf, "message", event.getFormattedMessage(), null); buf.append(COMMA); appendKeyValue(buf, "@timestamp", df.format(new Date(event.getTimeStamp())), null); buf.append(COMMA); // ---- fields ---- appendKeyValue(buf, "logger", event.getLoggerName(), null); buf.append(COMMA); appendKeyValue(buf, "level", event.getLevel().toString(), null); buf.append(COMMA); appendKeyValue(buf, "thread", event.getThreadName(), null); IThrowableProxy tp = event.getThrowableProxy(); if (tp != null) { buf.append(COMMA); String throwable = ThrowableProxyUtil.asString(tp); appendKeyValue(buf, "throwable", throwable, null); } if (locationInfo) { StackTraceElement[] callerDataArray = event.getCallerData(); if (callerDataArray != null && callerDataArray.length > callerStackIdx) { buf.append(COMMA); buf.append("\"location\":{"); StackTraceElement immediateCallerData = callerDataArray[callerStackIdx]; appendKeyValue(buf, "class", immediateCallerData.getClassName(), null); buf.append(COMMA); appendKeyValue(buf, "method", immediateCallerData.getMethodName(), null); buf.append(COMMA); appendKeyValue(buf, "file", immediateCallerData.getFileName(), null); buf.append(COMMA); appendKeyValue(buf, "line", Integer.toString(immediateCallerData.getLineNumber()), null); buf.append("}"); } } /* * <log4j:properties> <log4j:data name="name" value="value"/> * </log4j:properties> */ if (properties) { Map<String, String> propertyMap = event.getMDCPropertyMap(); if ((propertyMap != null) && (propertyMap.size() != 0)) { Set<Entry<String, String>> entrySet = propertyMap.entrySet(); buf.append(COMMA); buf.append("\"properties\":{"); Iterator<Entry<String, String>> i = entrySet.iterator(); while (i.hasNext()) { Entry<String, String> entry = i.next(); appendKeyValue(buf, entry.getKey(), entry.getValue(), null); if (i.hasNext()) { buf.append(COMMA); } } buf.append("}"); } } if(additionalFields != null) { for(AdditionalField field : additionalFields) { buf.append(COMMA); appendKeyValue(buf, field.getKey(), field.getValue(), mdc); } } buf.append("}"); return buf.toString(); }