Search in sources :

Example 16 with ThrowableInformation

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;
}
Also used : Category(org.apache.log4j.Category) LogEvent(io.fabric8.insight.log.LogEvent) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) Level(org.apache.log4j.Level) Date(java.util.Date) LocationInfo(org.apache.log4j.spi.LocationInfo)

Example 17 with ThrowableInformation

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);
    }
}
Also used : Instant(java.time.Instant) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) Level(org.apache.log4j.Level)

Example 18 with ThrowableInformation

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";
}
Also used : ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) LocationInfo(org.apache.log4j.spi.LocationInfo)

Example 19 with ThrowableInformation

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);
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with ThrowableInformation

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");
}
Also used : ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) Date(java.util.Date)

Aggregations

ThrowableInformation (org.apache.log4j.spi.ThrowableInformation)21 LocationInfo (org.apache.log4j.spi.LocationInfo)5 StringWriter (java.io.StringWriter)3 Date (java.util.Date)3 Level (org.apache.log4j.Level)3 LoggingEvent (org.apache.log4j.spi.LoggingEvent)3 IOException (java.io.IOException)2 NoRouteToHostException (java.net.NoRouteToHostException)2 Map (java.util.Map)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ContainerNode (com.fasterxml.jackson.databind.node.ContainerNode)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 IdeaApplication (com.intellij.idea.IdeaApplication)1 Application (com.intellij.openapi.application.Application)1 ErrorLogger (com.intellij.openapi.diagnostic.ErrorLogger)1 IdeaLoggingEvent (com.intellij.openapi.diagnostic.IdeaLoggingEvent)1 LogEvent (io.fabric8.insight.log.LogEvent)1 PrintWriter (java.io.PrintWriter)1 Instant (java.time.Instant)1