Search in sources :

Example 6 with ThrowableInformation

use of org.apache.log4j.spi.ThrowableInformation in project ChatGameFontificator by GlitchCog.

the class DebugAppender method append.

@Override
public void append(LoggingEvent event) {
    debugLogBox.log(this.layout.format(event));
    ThrowableInformation info = event.getThrowableInformation();
    if (info != null && info.getThrowable() != null) {
        Throwable t = info.getThrowable();
        debugLogBox.log(throwableToString(t));
    }
}
Also used : ThrowableInformation(org.apache.log4j.spi.ThrowableInformation)

Example 7 with ThrowableInformation

use of org.apache.log4j.spi.ThrowableInformation in project hadoop by apache.

the class Log4Json method toJson.

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

Example 8 with ThrowableInformation

use of org.apache.log4j.spi.ThrowableInformation in project ats-framework by Axway.

the class DbEventRequestProcessor method getLoggingMesage.

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

Example 9 with ThrowableInformation

use of org.apache.log4j.spi.ThrowableInformation in project intellij-community by JetBrains.

the class DialogAppender method appendToLoggers.

void appendToLoggers(@NotNull LoggingEvent event, @NotNull ErrorLogger[] errorLoggers) {
    if (myDialogRunnable != null) {
        return;
    }
    final IdeaLoggingEvent ideaEvent;
    final Object message = event.getMessage();
    if (message instanceof IdeaLoggingEvent) {
        ideaEvent = (IdeaLoggingEvent) message;
    } else {
        ThrowableInformation info = event.getThrowableInformation();
        if (info == null) {
            return;
        }
        ideaEvent = extractLoggingEvent(message, info.getThrowable());
    }
    for (int i = errorLoggers.length - 1; i >= 0; i--) {
        final ErrorLogger logger = errorLoggers[i];
        if (!logger.canHandle(ideaEvent)) {
            continue;
        }
        myDialogRunnable = () -> {
            try {
                logger.handle(ideaEvent);
            } finally {
                myDialogRunnable = null;
            }
        };
        final Application app = ApplicationManager.getApplication();
        if (app == null) {
            new Thread(myDialogRunnable, "dialog appender logger").start();
        } else {
            app.executeOnPooledThread(myDialogRunnable);
        }
        break;
    }
}
Also used : ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Application(com.intellij.openapi.application.Application) IdeaApplication(com.intellij.idea.IdeaApplication) ErrorLogger(com.intellij.openapi.diagnostic.ErrorLogger)

Example 10 with ThrowableInformation

use of org.apache.log4j.spi.ThrowableInformation in project lucene-solr by apache.

the class SolrLogLayout method _format.

public String _format(LoggingEvent event) {
    String message = (String) event.getMessage();
    if (message == null) {
        message = "";
    }
    StringBuilder sb = new StringBuilder(message.length() + 80);
    long now = event.timeStamp;
    long timeFromStart = now - startTime;
    long timeSinceLast = now - lastTime;
    lastTime = now;
    String shortClassName = getShortClassName(event.getLocationInformation().getClassName(), event.getLocationInformation().getMethodName());
    /***
     * sb.append(timeFromStart).append(' ').append(timeSinceLast);
     * sb.append(' ');
     * sb.append(record.getSourceClassName()).append('.').append(
     * record.getSourceMethodName()); sb.append(' ');
     * sb.append(record.getLevel());
     ***/
    SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo();
    SolrQueryRequest req = requestInfo == null ? null : requestInfo.getReq();
    SolrCore core = req == null ? null : req.getCore();
    ZkController zkController = null;
    CoreInfo info = null;
    if (core != null) {
        info = coreInfoMap.get(core.hashCode());
        if (info == null) {
            info = new CoreInfo();
            info.shortId = "C" + Integer.toString(CoreInfo.maxCoreNum++);
            coreInfoMap.put(core.hashCode(), info);
            if (sb.length() == 0)
                sb.append("ASYNC ");
            sb.append(" NEW_CORE " + info.shortId);
            sb.append(" name=" + core.getName());
            sb.append(" " + core);
        }
        zkController = core.getCoreContainer().getZkController();
        if (zkController != null) {
            if (info.url == null) {
                info.url = zkController.getBaseUrl() + "/" + core.getName();
                sb.append(" url=" + info.url + " node=" + zkController.getNodeName());
            }
            Map<String, Object> coreProps = getReplicaProps(zkController, core);
            if (info.coreProps == null || !coreProps.equals(info.coreProps)) {
                info.coreProps = coreProps;
                final String corePropsString = "coll:" + core.getCoreDescriptor().getCloudDescriptor().getCollectionName() + " core:" + core.getName() + " props:" + coreProps;
                sb.append(" " + info.shortId + "_STATE=" + corePropsString);
            }
        }
    }
    if (sb.length() > 0)
        sb.append('\n');
    sb.append(timeFromStart);
    // sb.append("\nL").append(record.getSequenceNumber()); // log number is
    // useful for sequencing when looking at multiple parts of a log file, but
    // ms since start should be fine.
    appendThread(sb, event);
    appendMDC(sb);
    if (info != null) {
        // core
        sb.append(' ').append(info.shortId);
    }
    if (shortClassName.length() > 0) {
        sb.append(' ').append(shortClassName);
    }
    if (event.getLevel() != Level.INFO) {
        sb.append(' ').append(event.getLevel());
    }
    sb.append(' ');
    appendMultiLineString(sb, message);
    ThrowableInformation thInfo = event.getThrowableInformation();
    if (thInfo != null) {
        Throwable th = event.getThrowableInformation().getThrowable();
        if (th != null) {
            sb.append(' ');
            String err = SolrException.toStr(th);
            String ignoredMsg = SolrException.doIgnore(th, err);
            if (ignoredMsg != null) {
                sb.append(ignoredMsg);
            } else {
                sb.append(err);
            }
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) ZkController(org.apache.solr.cloud.ZkController) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo)

Aggregations

ThrowableInformation (org.apache.log4j.spi.ThrowableInformation)11 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 NoRouteToHostException (java.net.NoRouteToHostException)2 LocationInfo (org.apache.log4j.spi.LocationInfo)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ContainerNode (com.fasterxml.jackson.databind.node.ContainerNode)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 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 ZkController (org.apache.solr.cloud.ZkController)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrCore (org.apache.solr.core.SolrCore)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1