/** * {@inheritDoc} */ public void format(final LoggingEvent event, final StringBuffer toAppendTo) { if (maxLines != 0) { ThrowableInformation information = event.getThrowableInformation(); if (information != null) { String[] stringRep = information.getThrowableStrRep(); int length = stringRep.length; if (maxLines < 0) { length += maxLines; } else if (length > maxLines) { length = maxLines; } for (int i = 0; i < length; i++) { String string = stringRep[i]; toAppendTo.append(string).append("\n"); } } } }
/** * @see PatternLayout#format(LoggingEvent) */ @Override public String format(LoggingEvent event) { String result = super.format(event); ThrowableInformation throwableInformation = event.getThrowableInformation(); if (throwableInformation != null) { result += getFilteredStacktrace(throwableInformation); } return result; }
/** * {@inheritDoc} */ @Override protected void append(LoggingEvent event) { final Throwable throwable; if (event.getThrowableInformation() == null) { throwable = null; } else { throwable = event.getThrowableInformation().getThrowable(); } LoggingHandler.addErrorLogToCounter(getLayout().format(event), throwable); }
/** * {@inheritDoc} */ public LoggingEvent rewrite(final LoggingEvent source) { if (!properties.isEmpty()) { Map rewriteProps = new HashMap(source.getProperties()); for(Iterator iter = properties.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = (Map.Entry) iter.next(); if (!rewriteProps.containsKey(entry.getKey())) { rewriteProps.put(entry.getKey(), entry.getValue()); } } return new LoggingEvent( source.getFQNOfLoggerClass(), source.getLogger() != null ? source.getLogger(): Logger.getLogger(source.getLoggerName()), source.getTimeStamp(), source.getLevel(), source.getMessage(), source.getThreadName(), source.getThrowableInformation(), source.getNDC(), source.getLocationInformation(), rewriteProps); } return source; }
/** * Create a copy of event, but append a stack trace to the message (if it exists). Then it escapes * the backslashes, tabs, newlines and quotes in its message as we are sending it as JSON and we * don't want any corruption of the JSON object. */ private LoggingEvent appendStackTraceToEvent(final LoggingEvent event) { String message = event.getMessage().toString(); // If there is a stack trace available, print it out if (event.getThrowableInformation() != null) { final String[] s = event.getThrowableStrRep(); for (final String line : s) { message += "\n" + line; } } message = message .replace("\\", "\\\\") .replace("\n", "\\n") .replace("\"", "\\\"") .replace("\t", "\\t"); final Throwable throwable = event.getThrowableInformation() == null ? null : event.getThrowableInformation().getThrowable(); return new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getTimeStamp(), event.getLevel(), message, throwable); } }
newMsg, source.getThreadName(), source.getThrowableInformation(), source.getNDC(), source.getLocationInformation(),
newMsg, source.getThreadName(), source.getThrowableInformation(), source.getNDC(), source.getLocationInformation(),
/** * @see PatternLayout#format(LoggingEvent) */ @Override public String format(LoggingEvent event) { String result = super.format(event); ThrowableInformation throwableInformation = event.getThrowableInformation(); if (throwableInformation != null) { result += getFilteredStacktrace(throwableInformation); } return result; }
@Override protected void append( LoggingEvent event ) { String s = layout.format( event ); if ( Level.DEBUG.equals( event.getLevel() ) ) { log.logDebug( s ); } else if ( Level.ERROR.equals( event.getLevel() ) || Level.FATAL.equals( event.getLevel() ) ) { Throwable t = event.getThrowableInformation() == null ? null : event.getThrowableInformation().getThrowable(); if ( t == null ) { log.logError( s ); } else { log.logError( s, t ); } } else if ( Level.TRACE.equals( event.getLevel() ) ) { log.logRowlevel( s ); } else if ( Level.OFF.equals( event.getLevel() ) ) { log.logMinimal( s ); } else { // ALL, WARN, INFO, or others log.logBasic( s ); } }
/** * Convert an event to JSON * * @param writer the destination writer * @param event the event -must not be null * @return the writer * @throws IOException on problems generating the JSON */ public Writer toJson(final Writer writer, final LoggingEvent event) throws IOException { ThrowableInformation ti = event.getThrowableInformation(); toJson(writer, event.getLoggerName(), event.getTimeStamp(), event.getLevel().toString(), event.getThreadName(), event.getRenderedMessage(), ti); return writer; }
private static LoggingEvent replaceEventMessage(LoggingEvent event, String message) { return new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getTimeStamp(), event.getLevel(), message, event.getThreadName(), event.getThrowableInformation(), event.getNDC(), event.getLocationInformation(), event.getProperties()); } }
LoggingEvent singleLoggingEvent = new LoggingEvent(loggingEvent.getFQNOfLoggerClass(), loggingEvent.getLogger(), loggingEvent.getTimeStamp(), loggingEvent.getLevel(), message, loggingEvent.getThreadName(), loggingEvent.getThrowableInformation(), loggingEvent.getNDC(), loggingEvent.getLocationInformation(), loggingEvent.getProperties());
if (event.getThrowableInformation() != null) { record.setThrownStackTrace(event.getThrowableInformation());
ThrowableInformation tinfo = event.getThrowableInformation();
ThrowableInformation throwableInformation = element.getThrowableInformation(); if (throwableInformation != null) { ThrowableFormatter renderer = new ThrowableFormatter();
/** * {@inheritDoc} */ public void format(final LoggingEvent event, final StringBuffer toAppendTo) { if (maxLines != 0) { ThrowableInformation information = event.getThrowableInformation(); if (information != null) { String[] stringRep = information.getThrowableStrRep(); int length = stringRep.length; if (maxLines < 0) { length += maxLines; } else if (length > maxLines) { length = maxLines; } for (int i = 0; i < length; i++) { String string = stringRep[i]; toAppendTo.append(string).append("\n"); } } } }
/** * Method from Log4j AppenderSkeleton that gets a call for all Log4J events. * @param event A logging event. * @see org.apache.log4j.AppenderSkeleton */ @Override public void append(final LoggingEvent event) { SwingUtilities.invokeLater(() -> this.insertText( this.layout.format(event), event.getLevel(), event.getThrowableInformation() )); }
@Override public void append(LoggingEvent event) { if (event == null) return; String line = this.layout.format(event); this.lines.add(line); if (event.getThrowableInformation() != null) { for (String t: event.getThrowableStrRep()) this.lines.add(t + "\n"); } clean(this.maxlines); }
@Override public String format(LoggingEvent loggingEvent) { String loggerName = loggingEvent.getLoggerName(); String level = loggingEvent.getLevel().toString(); String message = loggingEvent.getMessage().toString().trim(); if(!message.startsWith("{") && !message.startsWith("[")){ message = "\"" + message + "\""; } String threadName = loggingEvent.getThreadName(); Date timeStamp = new Date(loggingEvent.getTimeStamp()); String context = Context.toJSON(); ThrowableInformation throwableInformation = loggingEvent.getThrowableInformation(); String exception = ""; if(throwableInformation != null){ exception = ",\"exception\":{\"message\":\""; Throwable throwable = throwableInformation.getThrowable(); String exceptionMessage = throwable.getMessage() != null? throwable.getMessage(): ""; //need to be careful here, sanitizing, since the message may already contain a chunk of JSON, so escaping or cleaning double quotes is not prudent:) exception += sanitize(exceptionMessage, false, '\n', '\t', '\r') + "\",\"stacktrace\":\"" + escapeControlChars(Util.getStackTraceString(throwable)) + "\"}"; } String contextJson = context != null ? ",\"context\":" + context : ""; String timestampString = this.simpleDateFormat == null ? timeStamp.toString() : simpleDateFormat.format(timeStamp); return "{\"level\":\"" + level + "\",\"timestamp\":\"" + timestampString + "\",\"thread\":\"" + threadName + "\",\"logger\":\"" + loggerName + "\",\"message\":" + message + contextJson + exception + "}" + System.getProperty("line.separator"); }
/** * {@inheritDoc} */ public LoggingEvent rewrite(final LoggingEvent source) { if (!properties.isEmpty()) { Map rewriteProps = new HashMap(source.getProperties()); for(Iterator iter = properties.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = (Map.Entry) iter.next(); if (!rewriteProps.containsKey(entry.getKey())) { rewriteProps.put(entry.getKey(), entry.getValue()); } } return new LoggingEvent( source.getFQNOfLoggerClass(), source.getLogger() != null ? source.getLogger(): Logger.getLogger(source.getLoggerName()), source.getTimeStamp(), source.getLevel(), source.getMessage(), source.getThreadName(), source.getThrowableInformation(), source.getNDC(), source.getLocationInformation(), rewriteProps); } return source; }