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


Java ThrowableInformation類代碼示例

本文整理匯總了Java中org.apache.log4j.spi.ThrowableInformation的典型用法代碼示例。如果您正苦於以下問題:Java ThrowableInformation類的具體用法?Java ThrowableInformation怎麽用?Java ThrowableInformation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ThrowableInformation類屬於org.apache.log4j.spi包,在下文中一共展示了ThrowableInformation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testException

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
@Test
public void testException() throws Throwable {
  Exception e =
      new NoRouteToHostException("that box caught fire 3 years ago");
  ThrowableInformation ti = new ThrowableInformation(e);
  Log4Json l4j = new Log4Json();
  long timeStamp = Time.now();
  String outcome = l4j.toJson(new StringWriter(),
      "testException",
      timeStamp,
      "INFO",
      "quoted\"",
      "new line\n and {}",
      ti)
      .toString();
  println("testException", outcome);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:18,代碼來源:TestLog4Json.java

示例2: 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

示例3: getThrowableRepresentationFromLoggingEvent

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
/**
 * Extracts Stack trace of Throwable contained in LogginEvent, if there is
 * any
 * 
 * @param aLoggingEvent
 *            logging event
 * @return stack trace of throwable
 */
public String getThrowableRepresentationFromLoggingEvent(LoggingEvent aLoggingEvent) {
	// extract throwable information from loggingEvent if available
	ThrowableInformation throwableinfo = aLoggingEvent.getThrowableInformation();
	StringBuffer throwableStringBuffer = new StringBuffer();

	if (throwableinfo != null) {
		String[] lines = throwableinfo.getThrowableStrRep();
		for (int index = 0; index < lines.length; index++) {
			throwableStringBuffer = (StringBuffer) throwableStringBuffer.append(lines[index]
					+ "\r\n");
		}
	}
	String result = quotedString(throwableStringBuffer.toString());
	if (this.getThrowableMaxChars() != -1 && result.length() > this.getThrowableMaxChars()) {
		result = result.substring(0, this.getThrowableMaxChars() - 1);
	}

	return result;
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:28,代碼來源:JDBCLogger.java

示例4: 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

示例5: append

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
@Override
protected void append(final LoggingEvent loggingEvent) {
	final StringBuilder buf = new StringBuilder();
	buf.append(getLayout().format(loggingEvent));
	final ThrowableInformation ti = loggingEvent.getThrowableInformation();

	if (ti != null) {
		final String[] cause = ti.getThrowableStrRep();

		for (final String line : cause) {
			buf.append(line).append('\n');
		}
	}

	j2DClient.get().addEventLine(new HeaderLessEventLine(buf.toString(), NotificationType.CLIENT));
}
 
開發者ID:arianne,項目名稱:stendhal,代碼行數:17,代碼來源:GameConsoleAppender.java

示例6: format

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
/**
 * {@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");
      }
    }
  }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:25,代碼來源:ThrowableInformationPatternConverter.java

示例7: setupBeforeClass

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
@BeforeClass
public static void setupBeforeClass() throws Exception {
	Logger xenqtt = Logger.getLogger("xenqtt");
	assertNotNull(xenqtt);

	Appender console = Logger.getRootLogger().getAppender("console");
	assertNotNull(console);

	console.addFilter(new Filter() {
		@Override
		public int decide(LoggingEvent event) {
			entries.add(event.getRenderedMessage());

			ThrowableInformation info = event.getThrowableInformation();
			if (info != null) {
				Throwable t = info.getThrowable();
				if (t != null) {
					entries.add(t.getMessage());
				}
			}

			return Filter.ACCEPT;
		}
	});
}
 
開發者ID:TwoGuysFromKabul,項目名稱:xenqtt,代碼行數:26,代碼來源:LogTest.java

示例8: 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

示例9: prepareLoggingEvent

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
/**
 * Prepares the LoggingEvent for beeing processes in another thread, by saving away the NDC, MDC, thread name,  
 * throwable information and location information (if parameter getLocationInformation is true).   
 * 
 * @param loggingEvent the logging event to prepare.
 * @param getLocationInformation flag indicating if location information should be fetched for the logging event.
 * 
 * @since 2.0
 */
public static void prepareLoggingEvent(final LoggingEvent loggingEvent, final boolean getLocationInformation)
{
   // Set the NDC and thread name for the calling thread as these LoggingEvent fields were not set at event creation time.
   loggingEvent.getNDC();
   loggingEvent.getThreadName();
   // Get a copy of this thread's MDC.
   loggingEvent.getMDCCopy();
   ThrowableInformation throwableInformation =  loggingEvent.getThrowableInformation();
   if( throwableInformation != null )
   {
      // Make the ThrowableInformation of the LoggingEvent store away the representation of the stack trace.
      throwableInformation.getThrowableStrRep();
   }
   if( getLocationInformation ) 
   {
      loggingEvent.getLocationInformation();
   }
}
 
開發者ID:tolo,項目名稱:JServer,代碼行數:28,代碼來源:LogManager.java

示例10: 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

示例11: 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

示例12: exceptionInformation

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
/**
 * Pull out details of exception in a Hashmap (if they exist)
 * 
 * @param loggingEvent
 * @return
 */
protected void exceptionInformation(
        final LoggingEvent loggingEvent) {
    if (loggingEvent.getThrowableInformation() != null) {
        final ThrowableInformation throwableInformation = loggingEvent
                .getThrowableInformation();
        if (throwableInformation.getThrowable().getClass()
                .getCanonicalName() != null) {
            ExceptionField.put(EXCEPTION.CLASS, throwableInformation.getThrowable().getClass()
                    .getCanonicalName());
        }
        if (throwableInformation.getThrowable().getMessage() != null) {
            ExceptionField.put(EXCEPTION.MESSAGE, throwableInformation.getThrowable().getMessage());
        }
        if (throwableInformation.getThrowableStrRep() != null) {
            final String stackTrace = StringUtils.join(
                    throwableInformation.getThrowableStrRep(), "\n");
            ExceptionField.put(EXCEPTION.STACKTRACE, stackTrace);
        }
    }
}
 
開發者ID:stuart-warren,項目名稱:logit,代碼行數:27,代碼來源:Layout.java

示例13: toJson

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:21,代碼來源:Log4Json.java

示例14: testNestedException

import org.apache.log4j.spi.ThrowableInformation; //導入依賴的package包/類
@Test
public void testNestedException() throws Throwable {
  Exception e =
      new NoRouteToHostException("that box caught fire 3 years ago");
  Exception ioe = new IOException("Datacenter problems", e);
  ThrowableInformation ti = new ThrowableInformation(ioe);
  Log4Json l4j = new Log4Json();
  long timeStamp = Time.now();
  String outcome = l4j.toJson(new StringWriter(),
      "testNestedException",
      timeStamp,
      "INFO",
      "quoted\"",
      "new line\n and {}",
      ti)
      .toString();
  println("testNestedException", outcome);
  ContainerNode rootNode = Log4Json.parse(outcome);
  assertEntryEquals(rootNode, Log4Json.LEVEL, "INFO");
  assertEntryEquals(rootNode, Log4Json.NAME, "testNestedException");
  assertEntryEquals(rootNode, Log4Json.TIME, timeStamp);
  assertEntryEquals(rootNode, Log4Json.EXCEPTION_CLASS,
      ioe.getClass().getName());
  JsonNode node = assertNodeContains(rootNode, Log4Json.STACK);
  assertTrue("Not an array: " + node, node.isArray());
  node = assertNodeContains(rootNode, Log4Json.DATE);
  assertTrue("Not a string: " + node, node.isTextual());
  //rather than try and make assertions about the format of the text
  //message equalling another ISO date, this test asserts that the hypen
  //and colon characters are in the string.
  String dateText = node.getTextValue();
  assertTrue("No '-' in " + dateText, dateText.contains("-"));
  assertTrue("No '-' in " + dateText, dateText.contains(":"));

}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:36,代碼來源:TestLog4Json.java

示例15: 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


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