/* (non-Javadoc) * @see org.apache.log4j.Appender#close() */ public void close() { if (_consoleStream != null) { try { _consoleStream.flush(); _consoleStream.close(); IConsoleManager mgr = ConsolePlugin.getDefault().getConsoleManager(); mgr.removeConsoles(new IConsole[] {_consoleStream.getConsole()}); } catch (IOException ioe) { _consoleStream.println(Activator.getResourceString("MessageConsoleAppender.ErrorClosing")); ioe.printStackTrace(new PrintStream(_consoleStream)); } } }
// print to stream, lazily instantiating and opening console if necessary private void print(final LoggingEvent event) { // ensure in UI thread assert Display.getCurrent() != null; // ensure console view is open if (WorkbenchUtil.getView(IConsoleConstants.ID_CONSOLE_VIEW) == null) { try { IWorkbenchPage activePage = WorkbenchUtil.getActivePage(); if (activePage != null) { activePage.showView(IConsoleConstants.ID_CONSOLE_VIEW); } } catch (PartInitException pie) { // ignore for now } } // lazily instantiate console if necessary if (_consoleStream == null) { IConsoleManager mgr = ConsolePlugin.getDefault().getConsoleManager(); MessageConsole logConsole = new MessageConsole( Activator.getResourceString("MessageConsoleAppender.Log"), // $NON-NLS-1$ null); mgr.addConsoles(new IConsole[] {logConsole}); mgr.showConsoleView(logConsole); _consoleStream = logConsole.newMessageStream(); } // print message _consoleStream.print(getLayout().format(event)); if (getLayout().ignoresThrowable()) { String[] lines = event.getThrowableStrRep(); if (lines != null) { for (String line : lines) { _consoleStream.println(line); } } } }