src/jdk/nashorn/internal/runtime/Logging.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.runtime;
  27 
  28 import java.util.HashMap;

  29 import java.util.Map;
  30 import java.util.Map.Entry;
  31 import java.util.logging.ConsoleHandler;
  32 import java.util.logging.Formatter;
  33 import java.util.logging.Handler;
  34 import java.util.logging.Level;
  35 import java.util.logging.LogRecord;
  36 import java.util.logging.Logger;
  37 
  38 /**
  39  * Logging system for getting loggers for arbitrary subsystems as
  40  * specified on the command line. Supports all standard log levels
  41  *
  42  */
  43 public final class Logging {
  44 
  45     private Logging() {
  46     }
  47 
  48     /** Loggers */


 100         return logger;
 101     }
 102 
 103     /**
 104      * Initialization function that is called to instantiate the logging system. It takes
 105      * logger names (keys) and logging labels respectively
 106      *
 107      * @param map a map where the key is a logger name and the value a logging level
 108      * @throws IllegalArgumentException if level or names cannot be parsed
 109      */
 110     public static void initialize(final Map<String, String> map) throws IllegalArgumentException {
 111         try {
 112             for (final Entry<String, String> entry : map.entrySet()) {
 113                 Level level;
 114 
 115                 final String key   = entry.getKey();
 116                 final String value = entry.getValue();
 117                 if ("".equals(value)) {
 118                     level = Level.INFO;
 119                 } else {
 120                     level = Level.parse(value.toUpperCase());
 121                 }
 122 
 123                 final String name = Logging.lastPart(key);
 124                 final Logger logger = instantiateLogger(name, level);
 125 
 126                 Logging.loggers.put(name, logger);
 127             }
 128         } catch (final IllegalArgumentException | SecurityException e) {
 129             throw e;
 130         }
 131     }
 132 
 133     private static Logger instantiateLogger(final String name, final Level level) {
 134         final Logger logger = java.util.logging.Logger.getLogger(name);
 135         for (final Handler h : logger.getHandlers()) {
 136             logger.removeHandler(h);
 137         }
 138 
 139         logger.setLevel(level);
 140         logger.setUseParentHandlers(false);




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.runtime;
  27 
  28 import java.util.HashMap;
  29 import java.util.Locale;
  30 import java.util.Map;
  31 import java.util.Map.Entry;
  32 import java.util.logging.ConsoleHandler;
  33 import java.util.logging.Formatter;
  34 import java.util.logging.Handler;
  35 import java.util.logging.Level;
  36 import java.util.logging.LogRecord;
  37 import java.util.logging.Logger;
  38 
  39 /**
  40  * Logging system for getting loggers for arbitrary subsystems as
  41  * specified on the command line. Supports all standard log levels
  42  *
  43  */
  44 public final class Logging {
  45 
  46     private Logging() {
  47     }
  48 
  49     /** Loggers */


 101         return logger;
 102     }
 103 
 104     /**
 105      * Initialization function that is called to instantiate the logging system. It takes
 106      * logger names (keys) and logging labels respectively
 107      *
 108      * @param map a map where the key is a logger name and the value a logging level
 109      * @throws IllegalArgumentException if level or names cannot be parsed
 110      */
 111     public static void initialize(final Map<String, String> map) throws IllegalArgumentException {
 112         try {
 113             for (final Entry<String, String> entry : map.entrySet()) {
 114                 Level level;
 115 
 116                 final String key   = entry.getKey();
 117                 final String value = entry.getValue();
 118                 if ("".equals(value)) {
 119                     level = Level.INFO;
 120                 } else {
 121                     level = Level.parse(value.toUpperCase(Locale.ENGLISH));
 122                 }
 123 
 124                 final String name = Logging.lastPart(key);
 125                 final Logger logger = instantiateLogger(name, level);
 126 
 127                 Logging.loggers.put(name, logger);
 128             }
 129         } catch (final IllegalArgumentException | SecurityException e) {
 130             throw e;
 131         }
 132     }
 133 
 134     private static Logger instantiateLogger(final String name, final Level level) {
 135         final Logger logger = java.util.logging.Logger.getLogger(name);
 136         for (final Handler h : logger.getHandlers()) {
 137             logger.removeHandler(h);
 138         }
 139 
 140         logger.setLevel(level);
 141         logger.setUseParentHandlers(false);