jdk/src/share/classes/java/util/logging/LogManager.java
changeset 11274 7e7196757acd
parent 9700 fdbacf68f185
child 13578 cb435d74ab6b
equal deleted inserted replaced
11139:db0c2ff5e1ea 11274:7e7196757acd
   177                     String cname = null;
   177                     String cname = null;
   178                     try {
   178                     try {
   179                         cname = System.getProperty("java.util.logging.manager");
   179                         cname = System.getProperty("java.util.logging.manager");
   180                         if (cname != null) {
   180                         if (cname != null) {
   181                             try {
   181                             try {
   182                                 Class clz = ClassLoader.getSystemClassLoader().loadClass(cname);
   182                                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
   183                                 manager = (LogManager) clz.newInstance();
   183                                 manager = (LogManager) clz.newInstance();
   184                             } catch (ClassNotFoundException ex) {
   184                             } catch (ClassNotFoundException ex) {
   185                                 Class clz = Thread.currentThread().getContextClassLoader().loadClass(cname);
   185                                 Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(cname);
   186                                 manager = (LogManager) clz.newInstance();
   186                                 manager = (LogManager) clz.newInstance();
   187                             }
   187                             }
   188                         }
   188                         }
   189                     } catch (Exception ex) {
   189                     } catch (Exception ex) {
   190                         System.err.println("Could not load Logmanager \"" + cname + "\"");
   190                         System.err.println("Could not load Logmanager \"" + cname + "\"");
   198                     manager.rootLogger = manager.new RootLogger();
   198                     manager.rootLogger = manager.new RootLogger();
   199                     manager.addLogger(manager.rootLogger);
   199                     manager.addLogger(manager.rootLogger);
   200 
   200 
   201                     // Adding the global Logger. Doing so in the Logger.<clinit>
   201                     // Adding the global Logger. Doing so in the Logger.<clinit>
   202                     // would deadlock with the LogManager.<clinit>.
   202                     // would deadlock with the LogManager.<clinit>.
   203                     Logger.global.setLogManager(manager);
   203                     Logger.getGlobal().setLogManager(manager);
   204                     manager.addLogger(Logger.global);
   204                     manager.addLogger(Logger.getGlobal());
   205 
   205 
   206                     // We don't call readConfiguration() here, as we may be running
   206                     // We don't call readConfiguration() here, as we may be running
   207                     // very early in the JVM startup sequence.  Instead readConfiguration
   207                     // very early in the JVM startup sequence.  Instead readConfiguration
   208                     // will be called lazily in getLogManager().
   208                     // will be called lazily in getLogManager().
   209                     return null;
   209                     return null;
   413 
   413 
   414                 String names[] = parseClassNames(handlersPropertyName);
   414                 String names[] = parseClassNames(handlersPropertyName);
   415                 for (int i = 0; i < names.length; i++) {
   415                 for (int i = 0; i < names.length; i++) {
   416                     String word = names[i];
   416                     String word = names[i];
   417                     try {
   417                     try {
   418                         Class   clz = ClassLoader.getSystemClassLoader().loadClass(word);
   418                         Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(word);
   419                         Handler hdl = (Handler) clz.newInstance();
   419                         Handler  hdl = (Handler) clz.newInstance();
   420                         try {
   420                         try {
   421                             // Check if there is a property defining the
   421                             // Check if there is a property defining the
   422                             // this handler's level.
   422                             // this handler's level.
   423                             String levs = getProperty(word + ".level");
   423                             String levs = getProperty(word + ".level");
   424                             if (levs != null) {
   424                             if (levs != null) {
   780             try {
   780             try {
   781                 // Instantiate the named class.  It is its constructor's
   781                 // Instantiate the named class.  It is its constructor's
   782                 // responsibility to initialize the logging configuration, by
   782                 // responsibility to initialize the logging configuration, by
   783                 // calling readConfiguration(InputStream) with a suitable stream.
   783                 // calling readConfiguration(InputStream) with a suitable stream.
   784                 try {
   784                 try {
   785                     Class clz = ClassLoader.getSystemClassLoader().loadClass(cname);
   785                     Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
   786                     clz.newInstance();
   786                     clz.newInstance();
   787                     return;
   787                     return;
   788                 } catch (ClassNotFoundException ex) {
   788                 } catch (ClassNotFoundException ex) {
   789                     Class clz = Thread.currentThread().getContextClassLoader().loadClass(cname);
   789                     Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(cname);
   790                     clz.newInstance();
   790                     clz.newInstance();
   791                     return;
   791                     return;
   792                 }
   792                 }
   793             } catch (Exception ex) {
   793             } catch (Exception ex) {
   794                 System.err.println("Logging configuration class \"" + cname + "\" failed");
   794                 System.err.println("Logging configuration class \"" + cname + "\" failed");
   835             props = new Properties();
   835             props = new Properties();
   836             // Since we are doing a reset we no longer want to initialize
   836             // Since we are doing a reset we no longer want to initialize
   837             // the global handlers, if they haven't been initialized yet.
   837             // the global handlers, if they haven't been initialized yet.
   838             initializedGlobalHandlers = true;
   838             initializedGlobalHandlers = true;
   839         }
   839         }
   840         Enumeration enum_ = getLoggerNames();
   840         Enumeration<String> enum_ = getLoggerNames();
   841         while (enum_.hasMoreElements()) {
   841         while (enum_.hasMoreElements()) {
   842             String name = (String)enum_.nextElement();
   842             String name = enum_.nextElement();
   843             resetLogger(name);
   843             resetLogger(name);
   844         }
   844         }
   845     }
   845     }
   846 
   846 
   847 
   847 
   924         String names[] = parseClassNames("config");
   924         String names[] = parseClassNames("config");
   925 
   925 
   926         for (int i = 0; i < names.length; i++) {
   926         for (int i = 0; i < names.length; i++) {
   927             String word = names[i];
   927             String word = names[i];
   928             try {
   928             try {
   929                 Class clz = ClassLoader.getSystemClassLoader().loadClass(word);
   929                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(word);
   930                 clz.newInstance();
   930                 clz.newInstance();
   931             } catch (Exception ex) {
   931             } catch (Exception ex) {
   932                 System.err.println("Can't load config class \"" + word + "\"");
   932                 System.err.println("Can't load config class \"" + word + "\"");
   933                 System.err.println("" + ex);
   933                 System.err.println("" + ex);
   934                 // ex.printStackTrace();
   934                 // ex.printStackTrace();
  1022     // we return the defaultValue.
  1022     // we return the defaultValue.
  1023     Filter getFilterProperty(String name, Filter defaultValue) {
  1023     Filter getFilterProperty(String name, Filter defaultValue) {
  1024         String val = getProperty(name);
  1024         String val = getProperty(name);
  1025         try {
  1025         try {
  1026             if (val != null) {
  1026             if (val != null) {
  1027                 Class clz = ClassLoader.getSystemClassLoader().loadClass(val);
  1027                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(val);
  1028                 return (Filter) clz.newInstance();
  1028                 return (Filter) clz.newInstance();
  1029             }
  1029             }
  1030         } catch (Exception ex) {
  1030         } catch (Exception ex) {
  1031             // We got one of a variety of exceptions in creating the
  1031             // We got one of a variety of exceptions in creating the
  1032             // class or creating an instance.
  1032             // class or creating an instance.
  1043     // we return the defaultValue.
  1043     // we return the defaultValue.
  1044     Formatter getFormatterProperty(String name, Formatter defaultValue) {
  1044     Formatter getFormatterProperty(String name, Formatter defaultValue) {
  1045         String val = getProperty(name);
  1045         String val = getProperty(name);
  1046         try {
  1046         try {
  1047             if (val != null) {
  1047             if (val != null) {
  1048                 Class clz = ClassLoader.getSystemClassLoader().loadClass(val);
  1048                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(val);
  1049                 return (Formatter) clz.newInstance();
  1049                 return (Formatter) clz.newInstance();
  1050             }
  1050             }
  1051         } catch (Exception ex) {
  1051         } catch (Exception ex) {
  1052             // We got one of a variety of exceptions in creating the
  1052             // We got one of a variety of exceptions in creating the
  1053             // class or creating an instance.
  1053             // class or creating an instance.
  1161 
  1161 
  1162 
  1162 
  1163     // Private method to be called when the configuration has
  1163     // Private method to be called when the configuration has
  1164     // changed to apply any level settings to any pre-existing loggers.
  1164     // changed to apply any level settings to any pre-existing loggers.
  1165     synchronized private void setLevelsOnExistingLoggers() {
  1165     synchronized private void setLevelsOnExistingLoggers() {
  1166         Enumeration enum_ = props.propertyNames();
  1166         Enumeration<?> enum_ = props.propertyNames();
  1167         while (enum_.hasMoreElements()) {
  1167         while (enum_.hasMoreElements()) {
  1168             String key = (String)enum_.nextElement();
  1168             String key = (String)enum_.nextElement();
  1169             if (!key.endsWith(".level")) {
  1169             if (!key.endsWith(".level")) {
  1170                 // Not a level definition.
  1170                 // Not a level definition.
  1171                 continue;
  1171                 continue;