|
14 | 14 | *******************************************************************************/
|
15 | 15 | package org.eclipse.core.runtime;
|
16 | 16 |
|
| 17 | +import org.eclipse.core.internal.runtime.InternalPlatform; |
17 | 18 | import org.osgi.framework.Bundle;
|
| 19 | +import org.osgi.framework.FrameworkUtil; |
18 | 20 |
|
19 | 21 | /**
|
20 | 22 | * A log to which status events can be written. Logs appear on individual
|
@@ -132,4 +134,45 @@ default void error(String message) {
|
132 | 134 | default void error(String message, Throwable throwable) {
|
133 | 135 | log(new Status(IStatus.ERROR, getBundle().getSymbolicName(), message, throwable));
|
134 | 136 | }
|
| 137 | + |
| 138 | + /** |
| 139 | + * Returns the log for the given bundle. If no such log exists, one is created. |
| 140 | + * |
| 141 | + * @param bundle the bundle whose log is returned |
| 142 | + * @return the log for the given bundle |
| 143 | + * @since 3.28 |
| 144 | + */ |
| 145 | + public static ILog of(Bundle bundle) { |
| 146 | + return InternalPlatform.getDefault().getLog(bundle); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Returns the log for the bundle of the given class. If no such log exists, one |
| 151 | + * is created. |
| 152 | + * |
| 153 | + * @param clazz the class in a bundle whose log is returned |
| 154 | + * @return the log for the bundle to which the clazz belongs |
| 155 | + * |
| 156 | + * @since 3.28 |
| 157 | + */ |
| 158 | + public static ILog of(Class<?> clazz) { |
| 159 | + Bundle bundle = FrameworkUtil.getBundle(clazz); |
| 160 | + return InternalPlatform.getDefault().getLog(bundle); |
| 161 | + } |
| 162 | + |
| 163 | + /** |
| 164 | + * Returns the log for the bundle of the calling class. If no such log exists, |
| 165 | + * one is created. |
| 166 | + * |
| 167 | + * @return the log for the bundle to which the caller belongs |
| 168 | + * |
| 169 | + * @since 3.28 |
| 170 | + */ |
| 171 | + public static ILog get() { |
| 172 | + try { |
| 173 | + return of(InternalPlatform.STACK_WALKER.getCallerClass()); |
| 174 | + } catch (IllegalCallerException e) { |
| 175 | + return of(ILog.class); |
| 176 | + } |
| 177 | + } |
135 | 178 | }
|
0 commit comments