當前位置: 首頁>>代碼示例>>Java>>正文


Java ThrowableInformation.getThrowable方法代碼示例

本文整理匯總了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;

    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:23,代碼來源:DbEventRequestProcessor.java

示例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();

	}
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:20,代碼來源:DailyAutoRollingFileAppender.java

示例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;
}
 
開發者ID:stackify,項目名稱:stackify-log-log4j12,代碼行數:27,代碼來源:LoggingEventAdapter.java

示例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 "";
}
 
開發者ID:tolo,項目名稱:JServer,代碼行數:18,代碼來源:ExtendedPatternLayout.java

示例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();
}
 
開發者ID:NCIP,項目名稱:common-security-module,代碼行數:24,代碼來源:Utils.java

示例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;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:50,代碼來源:Log4Json.java

示例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);

}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:12,代碼來源:Log4JRuleHelper.java

示例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());
         }
     }
 }
 
開發者ID:d0k1,項目名稱:log4jmongo,代碼行數:39,代碼來源:AbstractBsonAppender.java

示例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));
    }
}
 
開發者ID:GlitchCog,項目名稱:ChatGameFontificator,代碼行數:12,代碼來源:DebugAppender.java

示例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());
}
 
開發者ID:micromagic,項目名稱:eterna,代碼行數:15,代碼來源:Log4jAppender.java

示例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;
}
 
開發者ID:lightoze,項目名稱:errbit-java,代碼行數:14,代碼來源:Log4jNoticeBuilder.java

示例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();
}
 
開發者ID:NCIP,項目名稱:common-security-module,代碼行數:16,代碼來源:Utils.java

示例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");
}
 
開發者ID:javalite,項目名稱:activejdbc,代碼行數:32,代碼來源:JsonLog4jLayout.java

示例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;
}
 
開發者ID:mp911de,項目名稱:logstash-gelf,代碼行數:10,代碼來源:Log4jLogEvent.java

示例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
	}
}
 
開發者ID:GreenDelta,項目名稱:olca-app,代碼行數:16,代碼來源:Console.java


注:本文中的org.apache.log4j.spi.ThrowableInformation.getThrowable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。