org.apache.log4j.spi.ThrowableInformation#getThrowable ( )源码实例Demo

下面列出了org.apache.log4j.spi.ThrowableInformation#getThrowable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ats-framework   文件: DbEventRequestProcessor.java
private String getLoggingMesage( LoggingEvent event ) {

        Throwable throwable = null;
        ThrowableInformation throwableInfo = event.getThrowableInformation();
        if (throwableInfo != null && throwableInfo.getThrowable() != null) {
            // logging through methods like error(new Exception);
            throwable = throwableInfo.getThrowable();
        } else if (event.getMessage() instanceof Throwable) {
            // logging through methods like error("some message", new Exception);
            throwable = (Throwable) event.getMessage();
        }

        // first format the message using the layout
        String message = layout.format(event);
        // then append the exception stack trace
        if (throwable != null) {
            message = getExceptionMsg(throwable, message);
        }

        return message;

    }
 
源代码2 项目: xian   文件: GelfMessageFactory.java
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;
    }
}
 
源代码3 项目: xian   文件: Log4jLogEvent.java
@Override
public Throwable getThrowable() {
    ThrowableInformation ti = loggingEvent.getThrowableInformation();
    if (ti != null) {
        return ti.getThrowable();
    }

    return null;
}
 
源代码4 项目: hadoop   文件: Log4Json.java
/**
 * Build a JSON entry from the parameters. This is public for testing.
 *
 * @param writer destination
 * @param loggerName logger name
 * @param timeStamp time_t value
 * @param level level string
 * @param threadName name of the thread
 * @param message rendered message
 * @param ti nullable thrown information
 * @return the writer
 * @throws IOException on any problem
 */
public Writer toJson(final Writer writer,
                     final String loggerName,
                     final long timeStamp,
                     final String level,
                     final String threadName,
                     final String message,
                     final ThrowableInformation ti) throws IOException {
  JsonGenerator json = factory.createJsonGenerator(writer);
  json.writeStartObject();
  json.writeStringField(NAME, loggerName);
  json.writeNumberField(TIME, timeStamp);
  Date date = new Date(timeStamp);
  json.writeStringField(DATE, dateFormat.format(date));
  json.writeStringField(LEVEL, level);
  json.writeStringField(THREAD, threadName);
  json.writeStringField(MESSAGE, message);
  if (ti != null) {
    //there is some throwable info, but if the log event has been sent over the wire,
    //there may not be a throwable inside it, just a summary.
    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) {
      json.writeString(row);
    }
    json.writeEndArray();
  }
  json.writeEndObject();
  json.flush();
  json.close();
  return writer;
}
 
源代码5 项目: big-c   文件: Log4Json.java
/**
 * Build a JSON entry from the parameters. This is public for testing.
 *
 * @param writer destination
 * @param loggerName logger name
 * @param timeStamp time_t value
 * @param level level string
 * @param threadName name of the thread
 * @param message rendered message
 * @param ti nullable thrown information
 * @return the writer
 * @throws IOException on any problem
 */
public Writer toJson(final Writer writer,
                     final String loggerName,
                     final long timeStamp,
                     final String level,
                     final String threadName,
                     final String message,
                     final ThrowableInformation ti) throws IOException {
  JsonGenerator json = factory.createJsonGenerator(writer);
  json.writeStartObject();
  json.writeStringField(NAME, loggerName);
  json.writeNumberField(TIME, timeStamp);
  Date date = new Date(timeStamp);
  json.writeStringField(DATE, dateFormat.format(date));
  json.writeStringField(LEVEL, level);
  json.writeStringField(THREAD, threadName);
  json.writeStringField(MESSAGE, message);
  if (ti != null) {
    //there is some throwable info, but if the log event has been sent over the wire,
    //there may not be a throwable inside it, just a summary.
    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) {
      json.writeString(row);
    }
    json.writeEndArray();
  }
  json.writeEndObject();
  json.flush();
  json.close();
  return writer;
}
 
源代码6 项目: ChatGameFontificator   文件: DebugAppender.java
@Override
public void append(LoggingEvent event)
{
    debugLogBox.log(this.layout.format(event));
    ThrowableInformation info = event.getThrowableInformation();
    if (info != null && info.getThrowable() != null)
    {
        Throwable t = info.getThrowable();
        debugLogBox.log(throwableToString(t));
    }
}
 
源代码7 项目: olca-app   文件: Console.java
private void tryPrintMessage(String message, ThrowableInformation info) {
	try {
		stream.println(message);
		if (info != null) {
			Throwable throwable = info.getThrowable();
			if (throwable != null) {
				stream.println(throwable.getMessage());
				throwable.printStackTrace(new PrintStream(stream));
			}
		}
	} catch (Exception e) {
	}
}
 
源代码8 项目: xio   文件: GlogLayout.java
@Override
public Throwable getThrowable(LoggingEvent record) {
  ThrowableInformation throwableInformation = record.getThrowableInformation();
  return throwableInformation != null ? throwableInformation.getThrowable() : null;
}