Search in sources :

Example 21 with ThrowableInformation

use of org.apache.log4j.spi.ThrowableInformation in project jbosstools-hibernate by jbosstools.

the class PluginLogAppender method append.

/**
 * Log event happened.
 * Translates level to status instance codes:
 * level > Level.ERROR - Status.ERROR
 * level > Level.WARN - Status.WARNING
 * level > Level.DEBUG - Status.INFO
 * default - Status.OK
 * @param event LoggingEvent instance
 */
public void append(LoggingEvent event) {
    if (this.layout == null) {
        this.errorHandler.error(ConsoleMessages.PluginLogAppender_missing_layout_for_appender + this.name, null, ErrorCode.MISSING_LAYOUT);
        return;
    }
    String text = this.layout.format(event);
    Throwable thrown = null;
    if (this.layout.ignoresThrowable()) {
        ThrowableInformation info = event.getThrowableInformation();
        if (info != null)
            thrown = info.getThrowable();
    }
    /*
		Level level = event.getLevel();
		int severity = IStatus.OK;

		if (level.toInt() >= Priority.ERROR_INT)
			severity = IStatus.ERROR;
		else
		if (level.toInt() >= Priority.WARN_INT)
			severity = IStatus.WARNING;
		else
		if (level.toInt() >= Priority.DEBUG_INT)
			severity = IStatus.INFO;


		this.pluginLog.log(new Status(severity,
		         this.pluginLog.getBundle().getSymbolicName(),
				 level.toInt(),text,thrown));*/
    Object peek = CurrentContext.peek();
    MessageConsoleStream stream = KnownConfigurations.getInstance().findLoggingStream((String) peek);
    if (stream != null) {
        stream.println(text);
        if (thrown != null) {
            StringWriter stringWriter = new StringWriter();
            thrown.printStackTrace(new PrintWriter(stringWriter));
            stream.println(stringWriter.getBuffer().toString());
        }
    }
}
Also used : StringWriter(java.io.StringWriter) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) PrintWriter(java.io.PrintWriter)

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