From 8fabc5c55da1e58516b5a3b2631a37414d4fbb63 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 30 Jan 2017 09:40:29 -0600 Subject: Bug 511268 - Tracing should honour -consoleLog Change-Id: Ib7ce9ab914f96f1ec739c8e88be8aaf4b6c269f2 Signed-off-by: Thomas Watson --- .../osgi/internal/debug/EclipseDebugTrace.java | 39 ++++++++++++++-------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'bundles') diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/EclipseDebugTrace.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/EclipseDebugTrace.java index 3a2fea17e..6d2378821 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/EclipseDebugTrace.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/EclipseDebugTrace.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corporation and others. + * Copyright (c) 2009, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,6 +15,7 @@ import java.security.AccessController; import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.Date; +import org.eclipse.core.runtime.adaptor.EclipseStarter; import org.eclipse.osgi.framework.util.SecureAction; import org.eclipse.osgi.service.debug.DebugTrace; @@ -93,17 +94,7 @@ class EclipseDebugTrace implements DebugTrace { /** DebugOptions are used to determine if the specified bundle symbolic name + option-path has debugging enabled */ private FrameworkDebugOptions debugOptions = null; - /** - * Construct a new EclipseDebugTrace for the specified bundle symbolic name and write messages to the specified - * trace file. The DebugOptions object will be used to determine if tracing should occur. - * - * @param bundleSymbolicName The symbolic name of the bundle being traced - * @param debugOptions Used to determine if the specified bundle symbolic name + option-path has tracing enabled - */ - EclipseDebugTrace(final String bundleSymbolicName, final FrameworkDebugOptions debugOptions) { - - this(bundleSymbolicName, debugOptions, null); - } + private final boolean consoleLog; /** * Construct a new EclipseDebugTrace for the specified bundle symbolic name and write messages to the specified @@ -114,7 +105,7 @@ class EclipseDebugTrace implements DebugTrace { * @param traceClass The class that the client is using to perform trace API calls */ EclipseDebugTrace(final String bundleSymbolicName, final FrameworkDebugOptions debugOptions, final Class traceClass) { - + this.consoleLog = "true".equals(debugOptions.getConfiguration().getConfiguration(EclipseStarter.PROP_CONSOLE_LOG)); //$NON-NLS-1$ this.traceClass = traceClass != null ? traceClass.getName() : null; this.debugOptions = debugOptions; this.bundleSymbolicName = bundleSymbolicName; @@ -643,14 +634,36 @@ class EclipseDebugTrace implements DebugTrace { /** * @throws IOException */ + @Override public void close() throws IOException { // We don't want to close System.out } + @Override public void write(byte[] var0, int var1, int var2) throws IOException { this.out.write(var0, var1, var2); } }; + } else if (consoleLog) { + out = new FilterOutputStream(out) { + @Override + public void write(int b) throws IOException { + System.out.write(b); + out.write(b); + } + + @Override + public void write(byte[] b) throws IOException { + System.out.write(b); + out.write(b); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + System.out.write(b, off, len); + out.write(b, off, len); + } + }; } return logForStream(out); } -- cgit v1.2.3