Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 651d56bc5e19421c288b834b0ad9fbf20f5d0139 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.eclipse.equinox.internal.p2.director.app;

import java.io.Closeable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.osgi.framework.log.FrameworkLog;

/**
 * Default implementation used for command line director invocations
 */
public class DefaultLog implements ILog, Closeable {
	private boolean failed = false;

	/**
	 * Sends logs to the {@link LogHelper standard p2 log}
	 */
	@Override
	public void log(IStatus status) {
		LogHelper.log(status);

		if (!status.isOK()) {
			failed = true;
		}
	}

	/**
	 * Sends messages to {@link System#out}
	 */
	@Override
	public void printOut(String message) {
		System.out.println(message);
	}

	/**
	 * Sends messages to {@link System#err}
	 */
	@Override
	public void printErr(String message) {
		System.err.println(message);
	}

	/**
	 * If failures were detected print a final message with the location of the log file
	 */
	@Override
	public void close() {
		if (!failed) {
			return;
		}

		FrameworkLog fwLog = ServiceHelper.getService(Activator.getContext(), FrameworkLog.class);
		if (fwLog == null) {
			return;
		}

		printErr("Failures loggaed in file: " + fwLog.getFile()); //$NON-NLS-1$
	}
}

Back to the top