changeset 2159:74f493fae483

6925868: Eliminate pack200's dependency on logging Summary: Replace j.u.l.Logger with sun.util.logging.PlatformLogger Reviewed-by: alanb, forax
author mchung
date Fri, 12 Feb 2010 11:33:33 -0800
parents 784e52734b8d
children 328c5d3974fe
files src/share/classes/com/sun/java/util/jar/pack/PackageReader.java src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java src/share/classes/com/sun/java/util/jar/pack/Utils.java
diffstat 3 files changed, 45 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java	Wed Feb 10 17:51:07 2010 -0800
+++ b/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java	Fri Feb 12 11:33:33 2010 -0800
@@ -27,7 +27,6 @@
 
 import java.io.*;
 import java.util.*;
-import java.util.logging.Level;
 import com.sun.java.util.jar.pack.Package.Class;
 import com.sun.java.util.jar.pack.Package.File;
 import com.sun.java.util.jar.pack.Package.InnerClass;
@@ -162,7 +161,7 @@
 
             ok = true;
         } catch (Exception ee) {
-            Utils.log.log(Level.WARNING, "Error on input: "+ee, ee);
+            Utils.log.warning("Error on input: "+ee, ee);
             if (verbose > 0)
                 Utils.log.info("Stream offsets:"+
                                  " served="+in.getBytesServed()+
--- a/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java	Wed Feb 10 17:51:07 2010 -0800
+++ b/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java	Fri Feb 12 11:33:33 2010 -0800
@@ -27,7 +27,6 @@
 
 import java.io.*;
 import java.util.*;
-import java.util.logging.Level;
 import com.sun.java.util.jar.pack.Package.Class;
 import com.sun.java.util.jar.pack.Package.File;
 import com.sun.java.util.jar.pack.Package.InnerClass;
@@ -84,7 +83,7 @@
 
             ok = true;
         } catch (Exception ee) {
-            Utils.log.log(Level.WARNING, "Error on output: "+ee, ee);
+            Utils.log.warning("Error on output: "+ee, ee);
             //if (verbose > 0)  ee.printStackTrace();
             // Write partial output only if we are verbose.
             if (verbose > 0)  finalOut.close();
--- a/src/share/classes/com/sun/java/util/jar/pack/Utils.java	Wed Feb 10 17:51:07 2010 -0800
+++ b/src/share/classes/com/sun/java/util/jar/pack/Utils.java	Fri Feb 12 11:33:33 2010 -0800
@@ -28,9 +28,10 @@
 import java.util.*;
 import java.util.jar.*;
 import java.util.zip.*;
-import java.util.logging.*;
 import java.io.*;
 
+import sun.util.logging.PlatformLogger;
+
 class Utils {
     static final String COM_PREFIX = "com.sun.java.util.jar.pack.";
     static final String METAINF    = "META-INF";
@@ -130,31 +131,53 @@
         = Boolean.getBoolean(Utils.COM_PREFIX+"nolog");
 
 
-    static final Logger log
-        = new Logger("java.util.jar.Pack200", null) {
-            public void log(LogRecord record) {
-                int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
-                if (verbose > 0) {
-                    if (nolog &&
-                        record.getLevel().intValue() < Level.WARNING.intValue()) {
-                        System.out.println(record.getMessage());
-                    } else {
-                        super.log(record);
-                    }
+    static class Pack200Logger {
+        private final String name;
+        private PlatformLogger log;
+        Pack200Logger(String name) {
+            this.name = name;
+        }
+
+        private synchronized PlatformLogger getLogger() {
+            if (log == null) {
+                log = PlatformLogger.getLogger(name);
+            }
+            return log;
+        }
+
+        public void warning(String msg, Object param) {
+            int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
+            if (verbose > 0) {
+                getLogger().warning(msg, param);
+            }
+        }
+
+        public void warning(String msg) {
+            warning(msg, null);
+        }
+
+        public void info(String msg) {
+            int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
+            if (verbose > 0) {
+                if (nolog) {
+                    System.out.println(msg);
+                } else {
+                    getLogger().info(msg);
                 }
             }
+        }
 
-            public void fine(String msg) {
-                int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
-                if (verbose > 0) {
-                        System.out.println(msg);
-                }
+        public void fine(String msg) {
+            int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
+            if (verbose > 0) {
+                    System.out.println(msg);
             }
-        };
-    static {
-        LogManager.getLogManager().addLogger(log);
+        }
     }
 
+    static final Pack200Logger log
+        = new Pack200Logger("java.util.jar.Pack200");
+
     // Returns the Max Version String of this implementation
     static String getVersionString() {
         return "Pack200, Vendor: Sun Microsystems, Version: " +