当前位置: 首页>>代码示例>>Java>>正文


Java LoggingEvent.getThrowableInformation方法代码示例

本文整理汇总了Java中org.apache.log4j.spi.LoggingEvent.getThrowableInformation方法的典型用法代码示例。如果您正苦于以下问题:Java LoggingEvent.getThrowableInformation方法的具体用法?Java LoggingEvent.getThrowableInformation怎么用?Java LoggingEvent.getThrowableInformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.log4j.spi.LoggingEvent的用法示例。


在下文中一共展示了LoggingEvent.getThrowableInformation方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: append

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
protected void append(LoggingEvent event) {
	if (isDoLog(event.getLevel())) {
		String logString = layout.format(event);

		ILog myLog = getLog();
		if (myLog != null) {
			String loggerName = event.getLoggerName();
			int severity = mapLevel(event.getLevel());
			final Throwable throwable = event.getThrowableInformation() != null ? event.getThrowableInformation()
					.getThrowable() : null;
			IStatus status = createStatus(severity, loggerName, logString, throwable);
			getLog().log(status);
		} else {
			// nothing to do (message should be logged to stdout by default appender)
		}
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:19,代码来源:EclipseLogAppender.java

示例2: getLoggingMesage

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的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.LoggingEvent; //导入方法依赖的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: append

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
public void append(LoggingEvent event) {
    if (event == null) return;
    String line = this.layout.format(event);
    this.lines.add(line);
    if (event.getThrowableInformation() != null) {
        for (String t: event.getThrowableStrRep()) this.lines.add(t + "\n");
    }
    clean(this.maxlines);
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:11,代码来源:LogAppender.java

示例5: FastLoggingEvent

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
public FastLoggingEvent(LoggingEvent event, int stackOffset) {
    super(event.getFQNOfLoggerClass(),
          event.getLogger(),
          event.getLevel(),
          event.getMessage(),
          (event.getThrowableInformation() != null ? event.getThrowableInformation().getThrowable() : null));
    this.event = event;
    this.stackOffset = stackOffset;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:10,代码来源:FastLoggingEvent.java

示例6: toJson

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的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

示例7: LogMessage

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
/**
 *  Constructs an instance from a Log4J event, using the specified layout.
 *
 *  @throws RuntimeException if any error occurred during formatting or conversion.
 *          Will include any root cause other than UnsupportedEncodingException.
 */
public LogMessage(LoggingEvent event, Layout layout)
{
    try
    {
        StringWriter out = new StringWriter(1024);
        out.write(layout.format(event));
        if ((event.getThrowableInformation() != null) && layout.ignoresThrowable())
        {
            for (String traceline : event.getThrowableStrRep())
            {
                out.write(traceline);
                out.write(Layout.LINE_SEP);
            }
        }
        out.close();

        this.timestamp = event.getTimeStamp();
        this.message = out.toString();
        this.messageBytes = this.message.getBytes("UTF-8");
    }
    catch (UnsupportedEncodingException e)
    {
        throw new RuntimeException("UnsupportedEncodingException when converting to UTF-8");
    }
    catch (Exception ex)
    {
        throw new RuntimeException("error creating LogMessage", ex);
    }
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:36,代码来源:LogMessage.java

示例8: appendersCalled

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的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

示例9: append

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
protected void append(LoggingEvent event) {
	if (!event.getLevel().isGreaterOrEqual(getMinLevel())) return;
	if (event.getLogger().equals(MessageLogAppender.class.getName())) return;
	
	MessageLog m = new MessageLog();
	m.setLevel(event.getLevel().toInt());

	String logger = event.getLoggerName();
	if (logger.indexOf('.') >= 0) logger = logger.substring(logger.lastIndexOf('.') + 1);
	m.setLogger(logger.length() > 255 ? logger.substring(0, 255) : logger);
	
	m.setMessage(event.getMessage() == null ? null : event.getMessage().toString());
	
	m.setTimeStamp(new Date(event.getTimeStamp()));
	
	m.setNdc(event.getNDC());
	
	String thread = event.getThreadName();
	m.setThread(thread == null ? null : thread.length() > 100 ? thread.substring(0, 100) : thread);
	
	Throwable t = (event.getThrowableInformation() != null ? event.getThrowableInformation().getThrowable() : null);
	if (t != null) {
		String ex = "";
		while (t != null) {
			String clazz = t.getClass().getName();
			if (clazz.indexOf('.') >= 0) clazz = clazz.substring(1 + clazz.lastIndexOf('.'));
			if (!ex.isEmpty()) ex += "\n";
			ex += clazz + ": " + t.getMessage();
			if (t.getStackTrace() != null && t.getStackTrace().length > 0)
				ex += " (at " + t.getStackTrace()[0].getFileName() + ":" + t.getStackTrace()[0].getLineNumber() + ")";
			t = t.getCause();
		}
		if (!ex.isEmpty())
			m.setException(ex);
	}
	
	getSaver().add(m);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:40,代码来源:MessageLogAppender.java

示例10: defaultLogFormat

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
static private Object defaultLogFormat(LoggingEvent loggingEvent) {

        LoggingEventX eventX = new LoggingEventX(loggingEvent.getFQNOfLoggerClass(), loggingEvent.getLogger()
                , loggingEvent.getTimeStamp(), loggingEvent.getLevel(), loggingEvent.getMessage(),
                loggingEvent.getThreadName(), loggingEvent.getThrowableInformation(), loggingEvent.getNDC(),
                loggingEvent.getLocationInformation(), loggingEvent.getProperties());

        eventX.setLogTime(new Date(loggingEvent.getTimeStamp()));
        eventX.setLogLevel(eventX.getLevel().toString());
        return eventX;
    }
 
开发者ID:Crab2died,项目名称:log4j-redis-appender,代码行数:12,代码来源:RedisAppender.java

示例11: countExceptionsWithMessage

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
public int countExceptionsWithMessage(final String text) {
  int count = 0;
  for (LoggingEvent e: getLog()) {
    ThrowableInformation t = e.getThrowableInformation();
    if (t != null) {
      String m = t.getThrowable().getMessage();
      if (m.contains(text)) {
        count++;
      }
    }
  }
  return count;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:LogVerificationAppender.java


注:本文中的org.apache.log4j.spi.LoggingEvent.getThrowableInformation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。