Skip to content

Commit

Permalink
4792: Stop using System.out/err.println and e.printStackTrace
Browse files Browse the repository at this point in the history
Reviewed-by: hirt
  • Loading branch information
Jean-Philippe Bempel committed Jul 22, 2021
1 parent b0b037a commit c6e0606
Show file tree
Hide file tree
Showing 41 changed files with 211 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private static void readGlobalConfig(XMLStreamReader streamReader, HashMap<Strin
streamReader.next();
}
} catch (XMLStreamException e) {
e.printStackTrace();
logger.log(Level.SEVERE, "Failed to parse global config", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -76,9 +76,9 @@ private static Method getRegisterMethod(Class<?> producerClass) {
return producerClass.getDeclaredMethod("addEvent", Class.class);
} catch (NoSuchMethodException | SecurityException e) {
// This should never happen
Agent.getLogger().severe("Failed to find the addEvent method of the producer.");
Agent.getLogger().severe("No BCI generated JFR events will be available.");
e.printStackTrace();
Agent.getLogger().log(Level.SEVERE,
"Failed to find the addEvent method of the producer. No BCI generated JFR events will be available.",
e);
}
return null;
}
Expand All @@ -92,10 +92,9 @@ private static Object createProducerReflectively(String name, String description
registerMethod.invoke(producer);
return producer;
} catch (Exception e) {
Agent.getLogger().severe(
"Failed to create producer for Oracle JDK7/8 JVM. Ensure that the JVM was started with -XX:+UnlockCommercialFeatures and -XX:+FlightRecorder.");
Agent.getLogger().severe("No BCI generated JFR events will be available.");
e.printStackTrace();
Agent.getLogger().log(Level.SEVERE,
"Failed to create producer for Oracle JDK7/8 JVM. Ensure that the JVM was started with -XX:+UnlockCommercialFeatures and -XX:+FlightRecorder. No BCI generated JFR events will be available.",
e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -35,6 +35,7 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

import org.eclipse.osgi.util.NLS;

Expand All @@ -51,6 +52,7 @@
* notification and shows the thread dump as an application alert, logs the thread dump, or both.
*/
public class TriggerActionThreadStackDump extends TriggerAction {
private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.alert"); //$NON-NLS-1$
private static final String XML_ELEMENT_LOG_TO_FILE = "log_to_file"; //$NON-NLS-1$
private static final String XML_ELEMENT_SHOW_APPLICATION_ALERT = "show_application_alert"; //$NON-NLS-1$
private static final String XML_ELEMENT_APPEND = "append"; //$NON-NLS-1$
Expand Down Expand Up @@ -82,7 +84,7 @@ public void handleNotificationEvent(TriggerEvent e) throws Exception {
InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
IDESupportToolkit.writeAsJob(jobName, file, stream, isAppend());
} else {
System.out.println(data);
LOGGER.info(data);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -45,6 +45,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.management.remote.JMXServiceURL;

Expand All @@ -61,6 +62,7 @@
*/
public class LocalConnectionDescriptor implements IConnectionDescriptor {

private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.browser.attach"); //$NON-NLS-1$
private static final String SELF_HOST_NAME = "localhost"; //$NON-NLS-1$
private static final String ATTACH_TIMED_OUT_ERROR_MESSAGE = "Timed out attempting to attach to target JVM!"; //$NON-NLS-1$
private static final String COULD_NOT_RETRIEVE_URL_ERROR_MESSAGE = "Could not retrieve the in-memory service URL after starting the in-memory agent!"; //$NON-NLS-1$
Expand Down Expand Up @@ -156,7 +158,7 @@ private void setAddress(String address) {
url = ConnectionToolkit.createServiceURL(SELF_HOST_NAME, 0);
} catch (MalformedURLException e) {
// Not going to happen...
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to parse url", e);
}
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -36,6 +36,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
Expand All @@ -48,6 +50,7 @@
* Class that creates a list of the available commands in the system.
*/
class CommandFactory {
private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.commands"); //$NON-NLS-1$
private static final String DESCRIPTION = "description"; //$NON-NLS-1$
private static final String IDENTIFIER = "identifier"; //$NON-NLS-1$
private static final String NAME = "name"; //$NON-NLS-1$
Expand Down Expand Up @@ -84,7 +87,7 @@ private static List<Command> createCommands(IConfigurationElement[] configuratio
try {
commands.add(createCommand(configurationElement));
} catch (Exception e) {
System.err.println(e.getMessage());
LOGGER.severe(e.getMessage());
}
}
}
Expand Down Expand Up @@ -119,7 +122,7 @@ private static void setCommandHelper(Command command, IConfigurationElement conf
command.setCommandHelper((ICommandHelper) o);
}
} catch (CoreException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to create type completion object", e);
throw new Exception("Error creating type completion object", e); //$NON-NLS-1$
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -152,7 +152,7 @@ private TwitterFactory createTwitterFactory() {
}
} catch (URISyntaxException e) {
// Should never happen...
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to parse URI", e);
}
return new TwitterFactory(cb.build());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -36,6 +36,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
Expand Down Expand Up @@ -153,8 +155,8 @@ public void selectDefaultBean() {
}
MBeanBrowserPlugin.getDefault().getLogger().warning("Couldn't find " + bean + " in MBean tree"); //$NON-NLS-1$ //$NON-NLS-2$
} catch (Exception e) {
e.printStackTrace();
MBeanBrowserPlugin.getDefault().getLogger().warning("Failed to select OperatingSystem bean: " + e); //$NON-NLS-1$
MBeanBrowserPlugin.getDefault().getLogger().log(Level.WARNING, "Failed to select OperatingSystem bean: ", //$NON-NLS-1$
e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -35,6 +35,8 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.resource.JFaceResources;
Expand Down Expand Up @@ -73,6 +75,7 @@
* Component that chooses a NotificationAction. Uses a StackLayout for each action
*/
public class ActionChooser {
private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.console.ui.notification.widget"); //$NON-NLS-1$

public interface ComponentFactory {
Composite createComponent(Composite parent, ITriggerAction action);
Expand Down Expand Up @@ -173,7 +176,7 @@ private void buildCache(TriggerRule notificationRule, NotificationRegistry notif
ITriggerAction na = af.createAction(name);
m_actionsCache.put(na.getName(), na);
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to create trigger action", e);
}
}
if (notificationRule.getAction() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -34,6 +34,8 @@

import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
Expand Down Expand Up @@ -68,6 +70,8 @@
* Component that selects NotificationConstraints. Uses a StackLayout
*/
public class ConstraintChooser {
private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.console.ui.notification.widget"); //$NON-NLS-1$

public class TriggerContentProvider extends AbstractStructuredContentProvider {
@Override
public Object[] getElements(Object inputElement) {
Expand Down Expand Up @@ -141,7 +145,7 @@ private void buildCache(TriggerRule notificationRule, NotificationRegistry notif
ITriggerConstraint nc = af.createConstraint(name);
m_constraintCache.put(nc.getName(), nc);
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to create trigger constraint", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -36,6 +36,8 @@
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.TableViewer;
Expand Down Expand Up @@ -64,6 +66,7 @@
import org.openjdk.jmc.ui.misc.MementoToolkit;

public class SubscriptionsSectionPart extends MCSectionPart {
private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.console.ui.subscriptions"); //$NON-NLS-1$

private class ClearStatisticsAction extends Action {
public ClearStatisticsAction() {
Expand Down Expand Up @@ -213,7 +216,7 @@ public void run() {
try {
Thread.sleep(DEFAULT_REFRESH_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Sleep interrupted", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Observable;
import java.util.Stack;
import java.util.logging.Logger;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
Expand Down Expand Up @@ -319,8 +320,9 @@ public void checkErrors() {
// NOTE: This will only keep one result per node, although many may have been found.
m_resultLookup.put(r.getObject(), r);
if (r.isError()) {
// FIXME: Get a logger when this is in a better bundle.
System.out.println(r.getObject() + ": " + r.getText()); //$NON-NLS-1$
Logger logger = Logger
.getLogger("org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml"); //$NON-NLS-1$
logger.severe(r.getObject() + ": " + r.getText()); //$NON-NLS-1$
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -40,6 +40,8 @@
import java.io.PrintWriter;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.SortedSet;
import java.util.TreeSet;

Expand Down Expand Up @@ -67,6 +69,8 @@
*/
@SuppressWarnings("nls")
public class PrintRecordingDescriptorAction implements IUserAction, IGraphical {
private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.flightrecorder.controlpanel.ui.actions"); //$NON-NLS-1$

private final IRecordingDescriptor recording;
private IFlightRecorderService flightRecorderService;
private final RecordingProvider rec;
Expand Down Expand Up @@ -106,7 +110,7 @@ private void printRecordingInfo(PrintWriter writer) {
printDivider(writer);
writer.flush();
} catch (Throwable t) {
t.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to print recording info", t);
}
}

Expand Down Expand Up @@ -218,11 +222,11 @@ public void execute() {
printRecordingInfo(System.err);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to execute print recording info", e);
} catch (ConnectionException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to execute print recording info", e);
} catch (ServiceNotAvailableException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "Failed to execute print recording info", e);
} finally {
IOToolkit.closeSilently(handle);
IOToolkit.closeSilently(newOut);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -110,10 +110,12 @@ public boolean accept(File dir, String name) {
repository.add(template);
} catch (IOException e) {
// FIXME: Better exception handling
e.printStackTrace();
ControlPanel.getDefault().getLogger().log(Level.SEVERE,
"Failed to load local template file " + file, e);
} catch (ParseException e) {
// FIXME: Better exception handling
e.printStackTrace();
ControlPanel.getDefault().getLogger().log(Level.SEVERE,
"Failed to parse local template file " + file, e);
}
}
}
Expand Down
Loading

0 comments on commit c6e0606

Please sign in to comment.