Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
11252342 | 2 | * Copyright (c) 2009, 2013 Ericsson |
5500a7f0 | 3 | * |
8c8bf09f ASL |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
5500a7f0 | 8 | * |
8c8bf09f ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
4918b8f2 | 13 | package org.eclipse.linuxtools.internal.tmf.core; |
8c8bf09f | 14 | |
9fa32496 | 15 | import org.eclipse.core.runtime.IStatus; |
e1ab8984 | 16 | import org.eclipse.core.runtime.Plugin; |
9fa32496 | 17 | import org.eclipse.core.runtime.Status; |
fc526aef | 18 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; |
cbd4ad82 | 19 | import org.osgi.framework.BundleContext; |
8c8bf09f ASL |
20 | |
21 | /** | |
cbd4ad82 FC |
22 | * The activator class controls the plug-in life cycle. No more than one such |
23 | * plug-in can exist at any time. | |
5500a7f0 FC |
24 | * <p> |
25 | * It also provides the plug-in's general logging facility and manages the | |
26 | * internal tracer. | |
8c8bf09f | 27 | */ |
8fd82db5 | 28 | public class Activator extends Plugin { |
8c8bf09f | 29 | |
11252342 | 30 | // ------------------------------------------------------------------------ |
8c8bf09f | 31 | // Attributes |
11252342 | 32 | // ------------------------------------------------------------------------ |
8c8bf09f | 33 | |
9fa32496 | 34 | /** |
5500a7f0 | 35 | * The plug-in ID |
9fa32496 | 36 | */ |
11252342 | 37 | public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.core"; //$NON-NLS-1$ |
8c8bf09f | 38 | |
11252342 | 39 | /** |
9fa32496 BH |
40 | * The shared instance |
41 | */ | |
11252342 | 42 | private static Activator fPlugin; |
5500a7f0 | 43 | |
11252342 | 44 | // ------------------------------------------------------------------------ |
8c8bf09f | 45 | // Constructors |
11252342 | 46 | // ------------------------------------------------------------------------ |
8c8bf09f | 47 | |
11252342 | 48 | /** |
9fa32496 BH |
49 | * Constructor |
50 | */ | |
11252342 AM |
51 | public Activator() { |
52 | setDefault(this); | |
53 | } | |
8c8bf09f | 54 | |
11252342 | 55 | // ------------------------------------------------------------------------ |
8c8bf09f | 56 | // Accessors |
11252342 | 57 | // ------------------------------------------------------------------------ |
8c8bf09f | 58 | |
11252342 | 59 | /** |
5500a7f0 | 60 | * Returns the TMF Core plug-in instance. |
9fa32496 | 61 | * |
5500a7f0 | 62 | * @return the TMF Core plug-in instance. |
9fa32496 | 63 | */ |
8fd82db5 | 64 | public static Activator getDefault() { |
cbd4ad82 | 65 | return fPlugin; |
8c8bf09f ASL |
66 | } |
67 | ||
9fa32496 | 68 | // Sets plug-in instance |
11252342 AM |
69 | private static void setDefault(Activator plugin) { |
70 | fPlugin = plugin; | |
71 | } | |
cbd4ad82 | 72 | |
11252342 | 73 | // ------------------------------------------------------------------------ |
12c155f5 | 74 | // Plugin |
11252342 AM |
75 | // ------------------------------------------------------------------------ |
76 | ||
77 | @Override | |
78 | public void start(BundleContext context) throws Exception { | |
79 | super.start(context); | |
80 | setDefault(this); | |
81 | TmfCoreTracer.init(); | |
fc526aef AM |
82 | /* Initialize the trace manager */ |
83 | TmfTraceManager.getInstance(); | |
11252342 AM |
84 | } |
85 | ||
86 | @Override | |
87 | public void stop(BundleContext context) throws Exception { | |
88 | TmfCoreTracer.stop(); | |
89 | setDefault(null); | |
90 | super.stop(context); | |
91 | } | |
92 | ||
93 | // ------------------------------------------------------------------------ | |
94 | // Log INFO | |
5500a7f0 FC |
95 | // ------------------------------------------------------------------------ |
96 | ||
9fa32496 BH |
97 | /** |
98 | * Logs a message with severity INFO in the runtime log of the plug-in. | |
5500a7f0 | 99 | * |
11252342 AM |
100 | * @param message |
101 | * A message to log | |
9fa32496 | 102 | */ |
5500a7f0 FC |
103 | public static void logInfo(String message) { |
104 | fPlugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); | |
9fa32496 | 105 | } |
5500a7f0 | 106 | |
9fa32496 | 107 | /** |
11252342 AM |
108 | * Logs a message and exception with severity INFO in the runtime log of the |
109 | * plug-in. | |
5500a7f0 | 110 | * |
11252342 AM |
111 | * @param message |
112 | * A message to log | |
113 | * @param exception | |
114 | * The corresponding exception | |
9fa32496 | 115 | */ |
5500a7f0 FC |
116 | public static void logInfo(String message, Throwable exception) { |
117 | fPlugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception)); | |
9fa32496 BH |
118 | } |
119 | ||
5500a7f0 FC |
120 | // ------------------------------------------------------------------------ |
121 | // Log WARNING | |
122 | // ------------------------------------------------------------------------ | |
123 | ||
9fa32496 | 124 | /** |
11252342 AM |
125 | * Logs a message and exception with severity WARNING in the runtime log of |
126 | * the plug-in. | |
5500a7f0 | 127 | * |
11252342 AM |
128 | * @param message |
129 | * A message to log | |
9fa32496 | 130 | */ |
5500a7f0 FC |
131 | public static void logWarning(String message) { |
132 | fPlugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message)); | |
9fa32496 | 133 | } |
5500a7f0 | 134 | |
9fa32496 | 135 | /** |
11252342 AM |
136 | * Logs a message and exception with severity WARNING in the runtime log of |
137 | * the plug-in. | |
5500a7f0 | 138 | * |
11252342 AM |
139 | * @param message |
140 | * A message to log | |
141 | * @param exception | |
142 | * The corresponding exception | |
9fa32496 | 143 | */ |
5500a7f0 FC |
144 | public static void logWarning(String message, Throwable exception) { |
145 | fPlugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception)); | |
9fa32496 BH |
146 | } |
147 | ||
5500a7f0 FC |
148 | // ------------------------------------------------------------------------ |
149 | // Log ERROR | |
150 | // ------------------------------------------------------------------------ | |
151 | ||
9fa32496 | 152 | /** |
11252342 AM |
153 | * Logs a message and exception with severity ERROR in the runtime log of |
154 | * the plug-in. | |
5500a7f0 | 155 | * |
11252342 AM |
156 | * @param message |
157 | * A message to log | |
9fa32496 | 158 | */ |
5500a7f0 FC |
159 | public static void logError(String message) { |
160 | fPlugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); | |
9fa32496 | 161 | } |
5500a7f0 | 162 | |
9fa32496 | 163 | /** |
11252342 AM |
164 | * Logs a message and exception with severity ERROR in the runtime log of |
165 | * the plug-in. | |
5500a7f0 | 166 | * |
11252342 AM |
167 | * @param message |
168 | * A message to log | |
169 | * @param exception | |
170 | * The corresponding exception | |
9fa32496 | 171 | */ |
5500a7f0 FC |
172 | public static void logError(String message, Throwable exception) { |
173 | fPlugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); | |
9fa32496 BH |
174 | } |
175 | ||
8c8bf09f | 176 | } |