本文整理汇总了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)
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}