Java Code Examples for org.apache.logging.log4j.core.LogEvent#getThrownProxy()
The following examples show how to use
org.apache.logging.log4j.core.LogEvent#getThrownProxy() .
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: MCRLogEventProcessor.java From mycore with GNU General Public License v3.0 | 6 votes |
@Override public void onNext(LogEvent event) { try { JsonObject logEvent = new JsonObject(); logEvent.addProperty("logLevel", event.getLevel().toString()); logEvent.addProperty("message", event.getMessage().getFormattedMessage()); String exception = null; if (event.getThrownProxy() != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); event.getThrownProxy().getThrowable().printStackTrace(pw); pw.close(); exception = sw.toString(); } logEvent.addProperty("exception", exception); logEvent.addProperty("time", event.getTimeMillis()); JsonObject json = new JsonObject(); json.addProperty("type", "log"); json.add("return", logEvent); submit(json); } finally { upstreamSubscrition.request(1); } }
Example 2
Source File: RollbarAppender.java From rollbar-java with MIT License | 6 votes |
@Override public void append(LogEvent event) { if (event.getLoggerName() != null && event.getLoggerName().startsWith(PACKAGE_NAME)) { LOGGER.warn("Recursive logging from [{}] for appender [{}].", event.getLoggerName(), getName()); return; } ThrowableProxy throwableProxy = event.getThrownProxy(); ThrowableWrapper rollbarThrowableWrapper = buildRollbarThrowableWrapper(throwableProxy); Map<String, Object> custom = this.buildCustom(event); String message = event.getMessage() != null ? event.getMessage().getFormattedMessage() : null; Level level = this.getLevel(event); rollbar.log(rollbarThrowableWrapper, custom, message, level, false); }
Example 3
Source File: ExtendedThrowablePatternConverter.java From logging-log4j2 with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final ThrowableProxy proxy = event.getThrownProxy(); final Throwable throwable = event.getThrown(); if ((throwable != null || proxy != null) && options.anyLines()) { if (proxy == null) { super.format(event, toAppendTo); return; } final int len = toAppendTo.length(); if (len > 0 && !Character.isWhitespace(toAppendTo.charAt(len - 1))) { toAppendTo.append(' '); } proxy.formatExtendedStackTraceTo(toAppendTo, options.getIgnorePackages(), options.getTextRenderer(), getSuffix(event), options.getSeparator()); } }
Example 4
Source File: Log4jLogEvent.java From logging-log4j2 with Apache License 2.0 | 6 votes |
public LogEventProxy(final LogEvent event, final boolean includeLocation) { this.loggerFQCN = event.getLoggerFqcn(); this.marker = event.getMarker(); this.level = event.getLevel(); this.loggerName = event.getLoggerName(); final Message temp = event.getMessage(); message = temp instanceof ReusableMessage ? memento((ReusableMessage) temp) : temp; this.timeMillis = event.getInstant().getEpochMillisecond(); this.nanoOfMillisecond = event.getInstant().getNanoOfMillisecond(); this.thrown = event.getThrown(); this.thrownProxy = event.getThrownProxy(); this.contextData = memento(event.getContextData()); this.contextStack = event.getContextStack(); this.source = includeLocation ? event.getSource() : null; this.threadId = event.getThreadId(); this.threadName = event.getThreadName(); this.threadPriority = event.getThreadPriority(); this.isLocationRequired = includeLocation; this.isEndOfBatch = event.isEndOfBatch(); this.nanoTime = event.getNanoTime(); }
Example 5
Source File: MutableLogEvent.java From logging-log4j2 with Apache License 2.0 | 6 votes |
/** * Initialize the fields of this {@code MutableLogEvent} from another event. * Similar in purpose and usage as {@link org.apache.logging.log4j.core.impl.Log4jLogEvent.LogEventProxy}, * but a mutable version. * <p> * This method is used on async logger ringbuffer slots holding MutableLogEvent objects in each slot. * </p> * * @param event the event to copy data from */ public void initFrom(final LogEvent event) { this.loggerFqcn = event.getLoggerFqcn(); this.marker = event.getMarker(); this.level = event.getLevel(); this.loggerName = event.getLoggerName(); this.thrown = event.getThrown(); this.thrownProxy = event.getThrownProxy(); this.instant.initFrom(event.getInstant()); // NOTE: this ringbuffer event SHOULD NOT keep a reference to the specified // thread-local MutableLogEvent's context data, because then two threads would call // ReadOnlyStringMap.clear() on the same shared instance, resulting in data corruption. this.contextData.putAll(event.getContextData()); this.contextStack = event.getContextStack(); this.source = event.isIncludeLocation() ? event.getSource() : null; this.threadId = event.getThreadId(); this.threadName = event.getThreadName(); this.threadPriority = event.getThreadPriority(); this.endOfBatch = event.isEndOfBatch(); this.includeLocation = event.isIncludeLocation(); this.nanoTime = event.getNanoTime(); setMessage(event.getMessage()); }
Example 6
Source File: RootThrowablePatternConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final ThrowableProxy proxy = event.getThrownProxy(); final Throwable throwable = event.getThrown(); if (throwable != null && options.anyLines()) { if (proxy == null) { super.format(event, toAppendTo); return; } final String trace = proxy.getCauseStackTraceAsString(options.getIgnorePackages(), options.getTextRenderer(), getSuffix(event), options.getSeparator()); final int len = toAppendTo.length(); if (len > 0 && !Character.isWhitespace(toAppendTo.charAt(len - 1))) { toAppendTo.append(' '); } if (!options.allLines() || !Strings.LINE_SEPARATOR.equals(options.getSeparator())) { final StringBuilder sb = new StringBuilder(); final String[] array = trace.split(Strings.LINE_SEPARATOR); final int limit = options.minLines(array.length) - 1; for (int i = 0; i <= limit; ++i) { sb.append(array[i]); if (i < limit) { sb.append(options.getSeparator()); } } toAppendTo.append(sb.toString()); } else { toAppendTo.append(trace); } } }
Example 7
Source File: EventLookup.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Looks up the value from the logging event. * @param event The current LogEvent. * @param key the key to be looked up. * @return The value of the specified log event field. */ @Override public String lookup(final LogEvent event, final String key) { switch (key) { case "Marker": { return event.getMarker() != null ? event.getMarker().getName() : null; } case "ThreadName": { return event.getThreadName(); } case "Level": { return event.getLevel().toString(); } case "ThreadId": { return Long.toString(event.getThreadId()); } case "Timestamp": { return Long.toString(event.getTimeMillis()); } case "Exception": { if (event.getThrown() != null) { return event.getThrown().getClass().getSimpleName(); } if (event.getThrownProxy() != null) { return event.getThrownProxy().getName(); } return null; } case "Logger": { return event.getLoggerName(); } case "Message": { return event.getMessage().getFormattedMessage(); } default: { return null; } } }
Example 8
Source File: ConsolePatternSelector.java From teku with Apache License 2.0 | 4 votes |
@Override public PatternFormatter[] getFormatters(final LogEvent event) { return omitStackTraces && event.getThrownProxy() != null ? omitStackTraceFormat : defaultFormat; }
Example 9
Source File: JsonPatternLayout.java From cf-java-logging-support with Apache License 2.0 | 4 votes |
private PatternSelector getSelector(LogEvent event) { if (event.getThrownProxy() != null || event.getThrown() != null) { return execptionSelector; } return markerSelector; }
Example 10
Source File: XPipeThrowablePatternConverter.java From x-pipe with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final ThrowableProxy proxy = event.getThrownProxy(); final Throwable throwable = event.getThrown(); //xpipe code if(throwable != null){ if(ExceptionUtils.isSocketIoException(event.getThrown()) || ExceptionUtils.xpipeExceptionLogMessage(throwable)){ toAppendTo.append("," + throwable.getClass() + ":" + throwable.getMessage()); return; } String extra = ExceptionUtils.extractExtraMessage(throwable); if(extra != null){ toAppendTo.append(String.format("\n[%s]", extra)); } } if ((throwable != null || proxy != null) && options.anyLines()) { if (proxy == null) { super.format(event, toAppendTo); return; } final String extStackTrace = proxy.getExtendedStackTraceAsString(options.getPackages()); final int len = toAppendTo.length(); if (len > 0 && !Character.isWhitespace(toAppendTo.charAt(len - 1))) { toAppendTo.append(' '); } if (!options.allLines() || !Constants.LINE_SEPARATOR.equals(options.getSeparator())) { final StringBuilder sb = new StringBuilder(); final String[] array = extStackTrace.split(Constants.LINE_SEPARATOR); final int limit = options.minLines(array.length) - 1; for (int i = 0; i <= limit; ++i) { sb.append(array[i]); if (i < limit) { sb.append(options.getSeparator()); } } toAppendTo.append(sb.toString()); } else { toAppendTo.append(extStackTrace); } } }
Example 11
Source File: Log4jLogEvent.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public Builder(final LogEvent other) { Objects.requireNonNull(other); if (other instanceof RingBufferLogEvent) { ((RingBufferLogEvent) other).initializeBuilder(this); return; } if (other instanceof MutableLogEvent) { ((MutableLogEvent) other).initializeBuilder(this); return; } this.loggerFqcn = other.getLoggerFqcn(); this.marker = other.getMarker(); this.level = other.getLevel(); this.loggerName = other.getLoggerName(); this.message = other.getMessage(); this.instant.initFrom(other.getInstant()); this.thrown = other.getThrown(); this.contextStack = other.getContextStack(); this.includeLocation = other.isIncludeLocation(); this.endOfBatch = other.isEndOfBatch(); this.nanoTime = other.getNanoTime(); // Avoid unnecessarily initializing thrownProxy, threadName and source if possible if (other instanceof Log4jLogEvent) { final Log4jLogEvent evt = (Log4jLogEvent) other; this.contextData = evt.contextData; this.thrownProxy = evt.thrownProxy; this.source = evt.source; this.threadId = evt.threadId; this.threadName = evt.threadName; this.threadPriority = evt.threadPriority; } else { if (other.getContextData() instanceof StringMap) { this.contextData = (StringMap) other.getContextData(); } else { if (this.contextData.isFrozen()) { this.contextData = ContextDataFactory.createContextData(); } else { this.contextData.clear(); } this.contextData.putAll(other.getContextData()); } this.thrownProxy = other.getThrownProxy(); this.source = other.getSource(); this.threadId = other.getThreadId(); this.threadName = other.getThreadName(); this.threadPriority = other.getThreadPriority(); } }
Example 12
Source File: Log4jLogEvent.java From logging-log4j2 with Apache License 2.0 | 3 votes |
/** * Take a snapshot of the specified {@code LogEvent}. * * @param event the event to take a snapshot of * @param includeLocation if true, this method will obtain caller location information * @return snapshot of the event as a {@code Serializable} object * @see #deserialize(Serializable) * @see #serialize(Log4jLogEvent, boolean) */ public static Serializable serialize(final LogEvent event, final boolean includeLocation) { if (event instanceof Log4jLogEvent) { event.getThrownProxy(); // ensure ThrowableProxy is initialized return new LogEventProxy((Log4jLogEvent) event, includeLocation); } return new LogEventProxy(event, includeLocation); }