]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java
50c4ff590c358e3af690609fd7c78ed5a3d49673
[simantics/platform.git] / bundles / org.simantics.platform.ui / src / org / simantics / platform / ui / internal / Activator.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.platform.ui.internal;
13 import java.io.PrintWriter;
14 import java.io.StringWriter;
15
16 import org.eclipse.ui.plugin.AbstractUIPlugin;
17 import org.osgi.framework.BundleContext;
18 import org.osgi.framework.ServiceReference;
19 import org.simantics.UnhandledExceptionService;
20 import org.simantics.platform.ui.SimanticsConsole;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class Activator extends AbstractUIPlugin {
25
26     public Activator() {
27     }
28
29     @Override
30     public void start(BundleContext context) throws Exception {
31
32         super.start(context);
33
34         SimanticsConsole console = SimanticsConsole.findConsole();
35         if(console != null) {
36             ServiceReference<?> ref = context.getServiceReference(UnhandledExceptionService.class.getName());
37             if (ref != null) {
38                 UnhandledExceptionService service = (UnhandledExceptionService) context.getService(ref);
39                 service.registerHandler(t -> {
40                     StringWriter sw = new StringWriter();
41                     PrintWriter pw = new PrintWriter(sw);
42                     t.printStackTrace(pw);
43                     console.write(sw.toString());
44                 });
45             }
46             ConsoleAppender ca = new ConsoleAppender(console);
47             ch.qos.logback.classic.Logger logbackLogger =
48                     (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
49             logbackLogger.addAppender(ca);
50             ca.start();
51         }
52
53     }
54
55 }