X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.platform.ui%2Fsrc%2Forg%2Fsimantics%2Fplatform%2Fui%2Finternal%2FActivator.java;fp=bundles%2Forg.simantics.platform.ui%2Fsrc%2Forg%2Fsimantics%2Fplatform%2Fui%2Finternal%2FActivator.java;h=50c4ff590c358e3af690609fd7c78ed5a3d49673;hb=04bf1d8e31c85530bcd47d41051362533997134e;hp=0000000000000000000000000000000000000000;hpb=4c6e2a31144508a830489706ad4f80f338d0c3ae;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java b/bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java new file mode 100644 index 000000000..50c4ff590 --- /dev/null +++ b/bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2019 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.platform.ui.internal; +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.simantics.UnhandledExceptionService; +import org.simantics.platform.ui.SimanticsConsole; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Activator extends AbstractUIPlugin { + + public Activator() { + } + + @Override + public void start(BundleContext context) throws Exception { + + super.start(context); + + SimanticsConsole console = SimanticsConsole.findConsole(); + if(console != null) { + ServiceReference ref = context.getServiceReference(UnhandledExceptionService.class.getName()); + if (ref != null) { + UnhandledExceptionService service = (UnhandledExceptionService) context.getService(ref); + service.registerHandler(t -> { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + console.write(sw.toString()); + }); + } + ConsoleAppender ca = new ConsoleAppender(console); + ch.qos.logback.classic.Logger logbackLogger = + (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); + logbackLogger.addAppender(ca); + ca.start(); + } + + } + +}