1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 /*******************************************************************************
13 * Copyright (c) 2000, 2006 IBM Corporation and others.
14 * All rights reserved. This program and the accompanying materials
15 * are made available under the terms of the Eclipse Public License v1.0
16 * which accompanies this distribution, and is available at
17 * http://www.eclipse.org/legal/epl-v10.html
20 * IBM Corporation - initial API and implementation
21 *******************************************************************************/
22 package org.simantics.message.internal;
24 import java.util.ArrayList;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.core.runtime.IStatus;
28 import org.eclipse.osgi.framework.log.FrameworkLog;
29 import org.eclipse.osgi.framework.log.FrameworkLogEntry;
30 import org.simantics.message.IDetailStatus;
31 import org.simantics.message.ILogListener;
34 * A log writer that writes log entries. See PlatformLogReader for reading logs
37 * Note that this class just provides a bridge from the old ILog interface to
38 * the OSGi FrameworkLog interface.
42 * Copied from <code>org.eclipse.core.internal.runtime.PlatformLogWriter</code>
43 * since the code was internal to eclipse. Support for {@link IDetailStatus} has
47 public class LogWriter implements ILogListener {
48 private final FrameworkLog frameworkLog;
50 public LogWriter(FrameworkLog frameworkLog) {
51 this.frameworkLog = frameworkLog;
55 * @see ILogListener#logging(IStatus, String)
57 public synchronized void logging(IStatus status, String plugin) {
58 frameworkLog.log(getLog(status));
61 protected FrameworkLogEntry getLog(IStatus status) {
62 Throwable t = status.getException();
63 ArrayList<FrameworkLogEntry> childlist = new ArrayList<FrameworkLogEntry>();
65 int stackCode = t instanceof CoreException ? 1 : 0;
66 // ensure a substatus inside a CoreException is properly logged
68 IStatus coreStatus = ((CoreException) t).getStatus();
69 if (coreStatus != null) {
70 childlist.add(getLog(coreStatus));
74 if (status.isMultiStatus()) {
75 IStatus[] children = status.getChildren();
76 for (int i = 0; i < children.length; i++) {
77 childlist.add(getLog(children[i]));
81 FrameworkLogEntry[] children = (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()]));
83 String message = status.getMessage();
84 if (status instanceof IDetailStatus) {
85 IDetailStatus ds = (IDetailStatus) status;
86 message = message + "\n!DETAILS " + ds.getDetailedDescription();
89 return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), message, stackCode, t, children);