本文整理匯總了Java中org.apache.log4j.spi.ThrowableInformation.getThrowable方法的典型用法代碼示例。如果您正苦於以下問題:Java ThrowableInformation.getThrowable方法的具體用法?Java ThrowableInformation.getThrowable怎麽用?Java ThrowableInformation.getThrowable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.log4j.spi.ThrowableInformation
的用法示例。
在下文中一共展示了ThrowableInformation.getThrowable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLoggingMesage
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
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: alarm
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
protected void alarm(LoggingEvent event, String level) {
String message = event.getRenderedMessage();
Throwable t = null;
{
ThrowableInformation throwableInformation = event.getThrowableInformation();
if (throwableInformation != null) {
t = throwableInformation.getThrowable();
}
}
try {
// this.sendToRobot(message, t);
this.robotService.errorlog(level, message, t);
}
catch (Exception e) {
e.printStackTrace();
}
}
示例3: getThrowable
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
* @see com.stackify.api.common.log.EventAdapter#getThrowable(java.lang.Object)
*/
@Override
public Throwable getThrowable(final LoggingEvent event) {
ThrowableInformation throwableInfo = event.getThrowableInformation();
if (throwableInfo != null) {
Throwable t = throwableInfo.getThrowable();
if (t != null) {
return t;
}
}
Object message = event.getMessage();
if (message != null) {
if (message instanceof Throwable) {
return (Throwable) message;
}
}
return null;
}
示例4: convert
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
public String convert(LoggingEvent event)
{
ThrowableInformation throwableInformation = event.getThrowableInformation();
if(throwableInformation != null)
{
Throwable error = throwableInformation.getThrowable();
if( error != null )
{
StringWriter strWriter = new StringWriter();
error.printStackTrace(new PrintWriter(strWriter));
return strWriter.toString().replaceAll("\\s+", " ");
}
}
return "";
}
示例5: getThrowable
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
public static String getThrowable(LoggingEvent le)
{
ThrowableInformation tinfo = le.getThrowableInformation();
Throwable t = null;
try
{
t = tinfo.getThrowable();
}
catch (Exception ex)
{
}
if (t == null)
{
return "";
}
java.io.StringWriter stringWriter;
stringWriter = new java.io.StringWriter();
t.printStackTrace(new java.io.PrintWriter(stringWriter));
return stringWriter.getBuffer().toString();
}
示例6: toJson
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
* 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;
}
示例7: appendersCalled
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
public void appendersCalled(LoggingEvent event) {
ThrowableInformation throwableInfo = event.getThrowableInformation();
String throwableName = null;
if (throwableInfo != null) {
Throwable throwable = throwableInfo.getThrowable();
throwableName = (throwable != null) ? throwable.getClass().getName() : null;
}
LogEventTracker.LogLevel level = LogEventTracker.LogLevel.valueOf(event.getLevel().toString());
tracker.track(level, (throwableInfo != null), throwableName);
}
示例8: addThrowableInformation
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
* Adds the ThrowableInformation object to an existing BSON object.
*
* @param bson
* The BSON object to add the throwable info to <i>(must not be null)</i>.
* @param throwableInfo
* The ThrowableInformation object to add to the BSON object <i>(may be null)</i>.
*/
@SuppressWarnings(value = "unchecked")
protected void addThrowableInformation(Document bson, final ThrowableInformation throwableInfo) {
if (throwableInfo != null) {
Throwable currentThrowable = throwableInfo.getThrowable();
@SuppressWarnings("rawtypes")
StringBuilder simpleThrowables = new StringBuilder();
List throwables = new BasicDBList();
while (currentThrowable != null) {
Document throwableBson = bsonifyThrowable(currentThrowable, simpleThrowables);
if (throwableBson != null) {
throwables.add(throwableBson);
}
currentThrowable = currentThrowable.getCause();
}
if (throwables.size() > 0) {
bson.put(KEY_THROWABLES, throwables);
bson.put(KEY_STACKTRACES, simpleThrowables.toString());
} else {
simpleThrowables.setLength(0);
for(String item : throwableInfo.getThrowableStrRep()){
simpleThrowables.append(item).append('\n');
}
bson.put(KEY_STACKTRACES, simpleThrowables.toString());
}
}
}
示例9: append
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
@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));
}
}
示例10: doAppend
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
public void doAppend(LoggingEvent event)
{
Throwable ex = null;
ThrowableInformation ti = event.getThrowableInformation();
if (ti != null)
{
ex = ti.getThrowable();
}
LocationInfo li = event.getLocationInformation();
this.listener.afterLog(String.valueOf(event.getMessage()), ex,
String.valueOf(event.getLevel()), event.getThreadName(),
li.getClassName(), li.getMethodName(), li.getFileName(),
li.getLineNumber());
}
示例11: throwable
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
public static Throwable throwable(LoggingEvent event) {
ThrowableInformation info = event.getThrowableInformation();
if (info != null) {
return info.getThrowable();
}
Object message = event.getMessage();
if (message instanceof Throwable) {
return (Throwable) message;
}
return null;
}
示例12: getThrowable
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
public static String getThrowable(LoggingEvent le) {
ThrowableInformation tinfo = le.getThrowableInformation();
Throwable t = null;
try{
t = tinfo.getThrowable();
}catch( Exception ex ){}
if ( t == null ){ return ""; }
java.io.StringWriter stringWriter;
stringWriter = new java.io.StringWriter();
t.printStackTrace( new java.io.PrintWriter(stringWriter) );
return stringWriter.getBuffer().toString();
}
示例13: format
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
@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");
}
示例14: getThrowable
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
@Override
public Throwable getThrowable() {
ThrowableInformation ti = loggingEvent.getThrowableInformation();
if (ti != null) {
return ti.getThrowable();
}
return null;
}
示例15: tryPrintMessage
import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
private void tryPrintMessage(String message,
ThrowableInformation throwableInformation) {
try {
logStream.println(message);
if (throwableInformation != null) {
Throwable throwable = throwableInformation.getThrowable();
if (throwable != null) {
logStream.println(throwable.getMessage());
throwable.printStackTrace(new PrintStream(logStream));
}
}
} catch (Exception e) {
// do nothing
}
}