8224594: Simplify jpackage Logging JDK-8200758-branch
authorherrick
Fri, 16 Aug 2019 06:55:31 -0400
branchJDK-8200758-branch
changeset 57776 783db59cd8d3
parent 57761 6019ac908578
child 57788 370bae2d88fe
8224594: Simplify jpackage Logging Reviewed-by: almatvee, asemenyuk
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacCertificate.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/CLIHelp.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/Log.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java
src/jdk.jpackage/share/classes/jdk/jpackage/main/Main.java
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java	Fri Aug 16 06:55:31 2019 -0400
@@ -141,9 +141,7 @@
 
                     return (vendor + "-" + appName).replaceAll("\\s", "");
                 } catch (Exception e) {
-                    if (Log.isDebug()) {
-                        e.printStackTrace();
-                    }
+                    Log.verbose(e);
                 }
                 return "unknown-MimeInfo.xml";
             },
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java	Fri Aug 16 06:55:31 2019 -0400
@@ -789,7 +789,7 @@
                             Files.setPosixFilePermissions(path, pfp);
                         }
                     } catch (IOException e) {
-                        Log.debug(e);
+                        Log.verbose(e);
                     }
                 })
                 .filter(p -> Files.isRegularFile(p) &&
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java	Fri Aug 16 06:55:31 2019 -0400
@@ -184,7 +184,7 @@
                 Log.error("Found more than one key matching '"  + key + "'");
                 return null;
             }
-            Log.debug("Using key '" + matchedKey + "'");
+            Log.verbose("Using key '" + matchedKey + "'");
             return matchedKey;
         } catch (IOException ioe) {
             Log.verbose(ioe);
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacCertificate.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacCertificate.java	Fri Aug 16 06:55:31 2019 -0400
@@ -112,7 +112,7 @@
                     "MMM dd kk:mm:ss yyyy z", Locale.ENGLISH);
             result = df.parse(output);
         } catch (IOException | ParseException ex) {
-            Log.debug(ex);
+            Log.verbose(ex);
         }
 
         return result;
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java	Fri Aug 16 06:55:31 2019 -0400
@@ -272,7 +272,8 @@
         protoDMG.getParentFile().mkdirs();
         finalDMG.getParentFile().mkdirs();
 
-        String hdiUtilVerbosityFlag = Log.isDebug() ? "-verbose" : "-quiet";
+        String hdiUtilVerbosityFlag = VERBOSE.fetchFrom(params) ?
+                "-verbose" : "-quiet";
 
         // create temp image
         ProcessBuilder pb = new ProcessBuilder(
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java	Fri Aug 16 06:55:31 2019 -0400
@@ -182,7 +182,7 @@
             IOUtils.deleteRecursive(
                     StandardBundlerParam.TEMP_ROOT.fetchFrom(params));
         } catch (IOException e) {
-            Log.debug(e.getMessage());
+            Log.verbose(e.getMessage());
         }
     }
 }
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java	Fri Aug 16 06:55:31 2019 -0400
@@ -114,7 +114,7 @@
         for (String arg : args) {
             argList.add(arg);
         }
-        Log.debug ("\njpackage argument list: \n" + argList + "\n");
+        Log.verbose ("\njpackage argument list: \n" + argList + "\n");
         pos = 0;
 
         deployParams = new DeployParams();
@@ -158,7 +158,7 @@
 
         VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
             setOptionValue("verbose", true);
-            Log.setVerbose(true);
+            Log.setVerbose();
         }),
 
         RESOURCE_DIR("resource-dir",
@@ -622,7 +622,7 @@
                     I18N.getString("message.bundle-created"),
                     bundler.getName()));
         } catch (ConfigException e) {
-            Log.debug(e);
+            Log.verbose(e);
             if (e.getAdvice() != null)  {
                 throw new PackagerException(e, "MSG_BundlerConfigException",
                         bundler.getName(), e.getMessage(), e.getAdvice());
@@ -632,7 +632,7 @@
                         bundler.getName(), e.getMessage());
             }
         } catch (RuntimeException re) {
-            Log.debug(re);
+            Log.verbose(re);
             throw new PackagerException(re, "MSG_BundlerRuntimeException",
                     bundler.getName(), re.toString());
         } finally {
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/CLIHelp.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/CLIHelp.java	Fri Aug 16 06:55:31 2019 -0400
@@ -46,7 +46,7 @@
         if (noArgs) {
             Log.info(I18N.getString("MSG_Help_no_args"));
         } else {
-            Platform platform = (Log.isDebug()) ?
+            Platform platform = (Log.isVerbose()) ?
                     Platform.UNKNOWN : Platform.getPlatform();
             String types;
             String pLaunchOptions;
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/Log.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/Log.java	Fri Aug 16 06:55:31 2019 -0400
@@ -41,12 +41,16 @@
         private PrintWriter out = null;
         private PrintWriter err = null;
 
-        public Logger(boolean v) {
-            verbose = v;
+        // verbose defaults to true unless environment variable JPACKAGE_DEBUG
+        // is set to true.
+        // Then it is only set to true by using --verbose jpackage option
+        
+        public Logger() {
+            verbose = ("true".equals(System.getenv("JPACKAGE_DEBUG")));
         }
 
-        public void setVerbose(boolean v) {
-            verbose = v;
+        public void setVerbose() {
+            verbose = true;
         }
 
         public boolean isVerbose() {
@@ -85,43 +89,26 @@
         }
 
         public void verbose(Throwable t) {
-            if (out != null && (Log.debug || verbose)) {
+            if (out != null && verbose) {
                 t.printStackTrace(out);
-            } else if (Log.debug || verbose) {
+            } else if (verbose) {
                 t.printStackTrace(System.out);
             }
         }
 
         public void verbose(String msg) {
-            if (out != null && (Log.debug || verbose)) {
+            if (out != null && verbose) {
                 out.println(msg);
-            } else if (Log.debug || verbose) {
-                System.out.println(msg);
-            }
-        }
-
-        public void debug(String msg) {
-            if (out != null && Log.debug) {
-                out.println(msg);
-            } else if (Log.debug) {
+            } else if (verbose) {
                 System.out.println(msg);
             }
         }
     }
 
     private static Logger delegate = null;
-    private static boolean debug =
-            "true".equals(System.getenv("JPACKAGE_DEBUG"));
 
-    public static void setLogger(Logger l) {
-        delegate = l;
-        if (l == null) {
-            delegate = new Logger(false);
-        }
-    }
-
-    public static Logger getLogger() {
-        return delegate;
+    public static void setLogger(Logger logger) {
+        delegate = (logger != null) ? logger : new Logger();
     }
 
     public static void flush() {
@@ -142,18 +129,14 @@
         }
     }
 
-    public static void setVerbose(boolean v) {
+    public static void setVerbose() {
         if (delegate != null) {
-            delegate.setVerbose(v);
+            delegate.setVerbose();
         }
     }
 
     public static boolean isVerbose() {
-        if (delegate != null) {
-            return delegate.isVerbose();
-        }
-
-        return false; // Off by default
+        return (delegate != null) ? delegate.isVerbose() : false;
     }
 
     public static void verbose(String msg) {
@@ -167,29 +150,4 @@
            delegate.verbose(t);
         }
     }
-
-    public static void debug(String msg) {
-        if (delegate != null) {
-           delegate.debug(msg);
-        }
-    }
-
-    public static void debug(Throwable t) {
-        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
-            try (PrintStream ps = new PrintStream(baos)) {
-                t.printStackTrace(ps);
-            }
-            debug(baos.toString());
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public static boolean isDebug() {
-        return debug;
-    }
-
-    public static void setDebug(boolean debug) {
-        Log.debug = debug;
-    }
 }
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java	Fri Aug 16 06:55:31 2019 -0400
@@ -497,7 +497,6 @@
         File applicationImage = null;
         if (PREDEFINED_APP_IMAGE.fetchFrom(params) != null) {
             applicationImage = PREDEFINED_APP_IMAGE.fetchFrom(params);
-            Log.debug("Using App Image from " + applicationImage);
             if (!applicationImage.exists()) {
                 throw new RuntimeException(
                         MessageFormat.format(I18N.getString(
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/main/Main.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/main/Main.java	Fri Aug 16 06:55:31 2019 -0400
@@ -46,8 +46,7 @@
      */
     public static void main(String... args) throws Exception {
         // Create logger with default system.out and system.err
-        Log.Logger logger = new Log.Logger(false);
-        Log.setLogger(logger);
+        Log.setLogger(null);
 
         int status = new jdk.jpackage.main.Main().execute(args);
         System.exit(status);
@@ -63,7 +62,7 @@
      */
     public int execute(PrintWriter out, PrintWriter err, String... args) {
         // Create logger with provided streams
-        Log.Logger logger = new Log.Logger(false);
+        Log.Logger logger = new Log.Logger();
         logger.setPrintWriter(out, err);
         Log.setLogger(logger);
 
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java	Thu Aug 15 08:03:41 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java	Fri Aug 16 06:55:31 2019 -0400
@@ -262,9 +262,7 @@
                     toolName, version));
             return version;
         } catch (Exception e) {
-            if (Log.isDebug()) {
-                Log.verbose(e);
-            }
+            Log.verbose(e);
             return null;
         }
     }