use of org.apache.log4j.spi.ThrowableInformation in project fabric8 by jboss-fuse.
the class Log4jLogQuery method toLogEvent.
protected LogEvent toLogEvent(LoggingEvent element) {
LogEvent answer = new LogEvent();
answer.setClassName(element.getFQNOfLoggerClass());
// TODO
// answer.setContainerName(element.get);
ThrowableInformation throwableInformation = element.getThrowableInformation();
if (throwableInformation != null) {
ThrowableFormatter renderer = new ThrowableFormatter();
String[] stack = renderer.doRender(throwableInformation.getThrowable());
if (stack == null) {
stack = element.getThrowableStrRep();
}
answer.setException(stack);
}
LocationInfo locationInformation = element.getLocationInformation();
if (locationInformation != null) {
answer.setFileName(locationInformation.getFileName());
answer.setClassName(locationInformation.getClassName());
answer.setMethodName(locationInformation.getMethodName());
answer.setLineNumber(locationInformation.getLineNumber());
}
Level level = element.getLevel();
if (level != null) {
answer.setLevel(level.toString());
}
// TODO
answer.setLogger(element.getLoggerName());
Category logger = element.getLogger();
Object message = element.getMessage();
if (message != null) {
// TODO marshal differently?
answer.setMessage(message.toString());
}
answer.setProperties(element.getProperties());
// TODO
answer.setSeq(element.getTimeStamp());
answer.setTimestamp(new Date(element.getTimeStamp()));
answer.setThread(element.getThreadName());
answer.setHost(getHostName());
return answer;
}
use of org.apache.log4j.spi.ThrowableInformation in project pwm by pwm-project.
the class LocalDBLog4jAppender method append.
@Override
protected void append(final LoggingEvent loggingEvent) {
final Object message = loggingEvent.getMessage();
final ThrowableInformation throwableInformation = loggingEvent.getThrowableInformation();
final Level level = loggingEvent.getLevel();
final Instant timeStamp = Instant.ofEpochMilli(loggingEvent.getTimeStamp());
final String sourceLogger = loggingEvent.getLogger().getName();
if (localDBLogger != null) {
final PwmLogEvent logEvent = PwmLogEvent.createPwmLogEvent(timeStamp, sourceLogger, message.toString(), null, null, null, throwableInformation == null ? null : throwableInformation.getThrowable(), PwmLogLevel.fromLog4jLevel(level));
localDBLogger.writeEvent(logEvent);
}
}
use of org.apache.log4j.spi.ThrowableInformation in project bender by Nextdoor.
the class BenderLayout method format.
@Override
public String format(LoggingEvent event) {
BenderLogEntry entry = new BenderLogEntry();
entry.threadName = event.getThreadName();
entry.posixTimestamp = event.getTimeStamp();
entry.timestamp = FORMATTER.print(entry.posixTimestamp);
entry.message = event.getRenderedMessage();
entry.level = event.getLevel().toString();
entry.logger = event.getLogger().getName();
entry.alias = ALIAS;
entry.version = VERSION;
if (event.getThrowableInformation() != null) {
final ThrowableInformation throwableInfo = event.getThrowableInformation();
ExceptionLog ex = new ExceptionLog();
if (throwableInfo.getThrowable().getClass().getCanonicalName() != null) {
ex.clazz = throwableInfo.getThrowable().getClass().getCanonicalName();
}
if (throwableInfo.getThrowable().getMessage() != null) {
ex.message = throwableInfo.getThrowable().getMessage();
}
if (throwableInfo.getThrowableStrRep() != null) {
Arrays.asList(throwableInfo.getThrowableStrRep()).forEach(m -> {
ex.stacktrace.add(m.replaceAll("\\t", " "));
});
}
entry.exception = ex;
}
LocationInfo locinfo = event.getLocationInformation();
entry.file = locinfo.getFileName();
entry.lineNumber = Integer.parseInt(locinfo.getLineNumber());
entry.method = locinfo.getMethodName();
entry.clazz = locinfo.getClassName();
return GSON.toJson(entry) + "\n";
}
use of org.apache.log4j.spi.ThrowableInformation in project phpinspectionsea by kalessil.
the class EAApplicationComponent method initComponent.
@Override
public void initComponent() {
final IdeaPluginDescriptor plugin = OpenapiPlatformUtil.getPluginById("com.kalessil.phpStorm.phpInspectionsEA");
if (null == plugin) {
return;
}
final EASettings settings = EASettings.getInstance();
/* dump new plugin version */
if (this.updated = !plugin.getVersion().equals(settings.getVersion())) {
settings.setVersion(plugin.getVersion());
}
/* collect exceptions */
if (!ApplicationManager.getApplication().isUnitTestMode()) {
final FileAppender appender = new FileAppender() {
@Override
public void append(@NotNull LoggingEvent event) {
if (settings.getSendCrashReports()) {
final ThrowableInformation exceptionDetails = event.getThrowableInformation();
if (exceptionDetails != null) {
AnalyticsUtil.registerLoggedException(settings.getVersion(), settings.getUuid(), exceptionDetails.getThrowable());
}
}
}
};
appender.setName("ea-exceptions-tracker");
Logger.getRootLogger().addAppender(appender);
}
}
use of org.apache.log4j.spi.ThrowableInformation in project activejdbc by javalite.
the class JsonLog4jLayout method format.
@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");
}
Aggregations