Refine search
if (loggerName != null && (!event.getLoggerName().equals(loggerName))) { return false; if (level != null && (!event.getLevel().equals(level))) { return false; if (event.getRenderedMessage().indexOf((String) messagePart) == -1) { return false; ThrowableInformation tinfo = event.getThrowableInformation(); if (tinfo == null || (!exceptionClass.isInstance(tinfo.getThrowable()))) { return false;
/** * {@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"); } } } }
/** Instantiate a LoggingEvent from the supplied parameters. <p>Except {@link #timeStamp} all the other fields of <code>LoggingEvent</code> are filled when actually needed. <p> @param logger The logger generating this event. @param timeStamp the timestamp of this logging event @param level The level of this event. @param message The message of this event. @param throwable The throwable of this event. */ public LoggingEvent(String fqnOfCategoryClass, Category logger, long timeStamp, Priority level, Object message, Throwable throwable) { this.fqnOfCategoryClass = fqnOfCategoryClass; this.logger = logger; this.categoryName = logger.getName(); this.level = level; this.message = message; if(throwable != null) { this.throwableInfo = new ThrowableInformation(throwable, logger); } this.timeStamp = timeStamp; }
Throwable thrown = ti.getThrowable(); String eclass = (thrown != null) ? thrown.getClass().getName() : ""; json.writeStringField(EXCEPTION_CLASS, eclass); String[] stackTrace = ti.getThrowableStrRep(); json.writeArrayFieldStart(STACK); for (String row : stackTrace) {
protected LogEvent toLogEvent(LoggingEvent element) { LogEvent answer = new LogEvent(); answer.setClassName(element.getFQNOfLoggerClass()); ThrowableInformation throwableInformation = element.getThrowableInformation(); if (throwableInformation != null) { ThrowableFormatter renderer = new ThrowableFormatter(); String[] stack = renderer.doRender(throwableInformation.getThrowable()); if (stack == null) { stack = element.getThrowableStrRep();
/** * 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); } }
@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} */ @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); }
@Override protected void append( final LoggingEvent loggingEvent ) { final Object message = loggingEvent.getMessage(); final ThrowableInformation throwableInformation = loggingEvent.getThrowableInformation(); final Level level = loggingEvent.getLevel(); final Instant timeStamp = Instant.ofEpochMilli( loggingEvent.getTimeStamp() ); final String sourceLogger = loggingEvent.getLogger().getName(); if ( localDBLogger != null ) { final PwmLogEvent logEvent = PwmLogEvent.createPwmLogEvent( timeStamp, sourceLogger, message.toString(), null, null, null, throwableInformation == null ? null : throwableInformation.getThrowable(), PwmLogLevel.fromLog4jLevel( level ) ); localDBLogger.writeEvent( logEvent ); } }
@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 ); } }
@Override protected void append(LoggingEvent event) { final LevelTag level = LevelTag.get(event.getLevel()); registry.counter(numMessages[level.ordinal()]).increment(); ThrowableInformation info = event.getThrowableInformation(); if (info != null) { LocationInfo loc = event.getLocationInformation(); final String file = (loc == null) ? "unknown" : loc.getFileName(); Id stackTraceId = numStackTraces[level.ordinal()] .withTag("exception", info.getThrowable().getClass().getSimpleName()) .withTag("file", file); registry.counter(stackTraceId).increment(); } }
/** Return this event's throwable's string[] representaion. */ public String[] getThrowableStrRep() { if(throwableInfo == null) return null; else return throwableInfo.getThrowableStrRep(); }
private org.apache.log4j.spi.LoggingEvent toLog4jEvent(LoggingEvent event, Level log4jLevel) { FormattingTuple ft = MessageFormatter.format(event.getMessage(), event.getArgumentArray(), event.getThrowable()); LocationInfo locationInfo = new LocationInfo(NA_SUBST, NA_SUBST, NA_SUBST, "0"); ThrowableInformation ti = null; Throwable t = ft.getThrowable(); if (t != null) ti = new ThrowableInformation(t); org.apache.log4j.spi.LoggingEvent log4jEvent = new org.apache.log4j.spi.LoggingEvent(FQCN, logger, event.getTimeStamp(), log4jLevel, ft.getMessage(), event.getThreadName(), ti, null, locationInfo, null); return log4jEvent; }
private static String extractStacktrace(ThrowableInformation throwableInformation) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Throwable t = throwableInformation.getThrowable(); if (t != null) { t.printStackTrace(pw); return sw.toString(); } else { return null; } } }
/** * Returns the stacktrace of the given exception as String.<p> * * @param e the exception * * @return the stacktrace as String */ private String formatStackTrace(Throwable e) { StringBuffer result = new StringBuffer(64); for (String s : new ThrowableInformation(e).getThrowableStrRep()) { result.append(s + "\n"); } return result.toString(); }
private static final ThrowableInformation toThrownInformation( final Throwable thrown ) { ThrowableInformation info = null; if( thrown != null ) { info = new ThrowableInformation( thrown ); } return info; }
@Override public Throwable getThrowable() { ThrowableInformation ti = loggingEvent.getThrowableInformation(); if (ti != null) { return ti.getThrowable(); } return null; }
@Override protected void append(LoggingEvent le) { if((le.getLevel() == Level.ERROR && !ignoreErrors) || (le.getLevel() == Level.WARN && !ignoreWarnings) ) { throw new RuntimeException(le.getThrowableInformation().getThrowable()); } }
/** Return this event's throwable's string[] representaion. */ public String[] getThrowableStrRep() { if(throwableInfo == null) return null; else return throwableInfo.getThrowableStrRep(); }
if (throwableInformation == null || !(throwableInformation.getThrowable() instanceof IgnoreMessageException)) { consoleTextPane.append(message, TRACE); javaTextPane.getProxy().setCaretPosition(javaTextPane.getProxy().getDocument().getLength()); if (throwableInformation != null && throwableInformation.getThrowableStrRep() != null) { for (String rep: throwableInformation.getThrowableStrRep()) { javaTextPane.append(rep, ERROR);