< prev index next >

src/java.logging/share/classes/java/util/logging/LogManager.java

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.logging;
  27 
  28 import java.io.*;
  29 import java.util.*;
  30 import java.security.*;
  31 import java.lang.ref.ReferenceQueue;
  32 import java.lang.ref.WeakReference;
  33 import java.util.concurrent.ConcurrentHashMap;
  34 import java.nio.file.Paths;
  35 import java.util.concurrent.CopyOnWriteArrayList;
  36 import java.util.concurrent.locks.ReentrantLock;
  37 import java.util.function.BiFunction;
  38 import java.util.function.Function;
  39 import java.util.function.Predicate;
  40 import java.util.stream.Collectors;
  41 import java.util.stream.Stream;
  42 import jdk.internal.access.JavaAWTAccess;
  43 import jdk.internal.access.SharedSecrets;
  44 import sun.util.logging.internal.LoggingProviderImpl;
  45 import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
  46 
  47 /**
  48  * There is a single global LogManager object that is used to
  49  * maintain a set of shared state about Loggers and log services.
  50  * <p>
  51  * This LogManager object:
  52  * <ul>
  53  * <li> Manages a hierarchical namespace of Logger objects.  All
  54  *      named Loggers are stored in this namespace.
  55  * <li> Manages a set of logging control properties.  These are
  56  *      simple key-value pairs that can be used by Handlers and
  57  *      other logging objects to configure themselves.
  58  * </ul>
  59  * <p>
  60  * The global LogManager object can be retrieved using LogManager.getLogManager().
  61  * The LogManager object is created during class initialization and
  62  * cannot subsequently be changed.
  63  * <p>


 436         if (!readPrimordialConfiguration) {
 437             // If System.in/out/err are null, it's a good
 438             // indication that we're still in the
 439             // bootstrapping phase
 440             if (System.out == null) {
 441                 return;
 442             }
 443             readPrimordialConfiguration = true;
 444             try {
 445                 readConfiguration();
 446 
 447                 // Platform loggers begin to delegate to java.util.logging.Logger
 448                 jdk.internal.logger.BootstrapLogger.redirectTemporaryLoggers();
 449 
 450             } catch (Exception ex) {
 451                 assert false : "Exception raised while reading logging configuration: " + ex;
 452             }
 453         }
 454     }
 455 
 456     // LoggerContext maps from AppContext
 457     private WeakHashMap<Object, LoggerContext> contextsMap = null;
 458 
 459     // Returns the LoggerContext for the user code (i.e. application or AppContext).
 460     // Loggers are isolated from each AppContext.
 461     private LoggerContext getUserContext() {
 462         LoggerContext context = null;
 463 
 464         SecurityManager sm = System.getSecurityManager();
 465         JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
 466         if (sm != null && javaAwtAccess != null) {
 467             // for each applet, it has its own LoggerContext isolated from others
 468             final Object ecx = javaAwtAccess.getAppletContext();
 469             if (ecx != null) {
 470                 synchronized (javaAwtAccess) {
 471                     // find the AppContext of the applet code
 472                     // will be null if we are in the main app context.
 473                     if (contextsMap == null) {
 474                         contextsMap = new WeakHashMap<>();
 475                     }
 476                     context = contextsMap.get(ecx);
 477                     if (context == null) {
 478                         // Create a new LoggerContext for the applet.
 479                         context = new LoggerContext();
 480                         contextsMap.put(ecx, context);
 481                     }
 482                 }
 483             }
 484         }
 485         // for standalone app, return userContext
 486         return context != null ? context : userContext;
 487     }
 488 
 489     // The system context.
 490     final LoggerContext getSystemContext() {
 491         return systemContext;
 492     }
 493 
 494     private List<LoggerContext> contexts() {
 495         List<LoggerContext> cxs = new ArrayList<>();
 496         cxs.add(getSystemContext());
 497         cxs.add(getUserContext());
 498         return cxs;
 499     }
 500 
 501     // Find or create a specified logger instance. If a logger has
 502     // already been created with the given name it is returned.
 503     // Otherwise a new logger instance is created and registered
 504     // in the LogManager global namespace.
 505     // This method will always return a non-null Logger object.
 506     // Synchronization is not required here. All synchronization for




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.logging;
  27 
  28 import java.io.*;
  29 import java.util.*;
  30 import java.security.*;
  31 import java.lang.ref.ReferenceQueue;
  32 import java.lang.ref.WeakReference;
  33 import java.util.concurrent.ConcurrentHashMap;
  34 import java.nio.file.Paths;
  35 import java.util.concurrent.CopyOnWriteArrayList;
  36 import java.util.concurrent.locks.ReentrantLock;
  37 import java.util.function.BiFunction;
  38 import java.util.function.Function;
  39 import java.util.function.Predicate;
  40 import java.util.stream.Collectors;
  41 import java.util.stream.Stream;


  42 import sun.util.logging.internal.LoggingProviderImpl;
  43 import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
  44 
  45 /**
  46  * There is a single global LogManager object that is used to
  47  * maintain a set of shared state about Loggers and log services.
  48  * <p>
  49  * This LogManager object:
  50  * <ul>
  51  * <li> Manages a hierarchical namespace of Logger objects.  All
  52  *      named Loggers are stored in this namespace.
  53  * <li> Manages a set of logging control properties.  These are
  54  *      simple key-value pairs that can be used by Handlers and
  55  *      other logging objects to configure themselves.
  56  * </ul>
  57  * <p>
  58  * The global LogManager object can be retrieved using LogManager.getLogManager().
  59  * The LogManager object is created during class initialization and
  60  * cannot subsequently be changed.
  61  * <p>


 434         if (!readPrimordialConfiguration) {
 435             // If System.in/out/err are null, it's a good
 436             // indication that we're still in the
 437             // bootstrapping phase
 438             if (System.out == null) {
 439                 return;
 440             }
 441             readPrimordialConfiguration = true;
 442             try {
 443                 readConfiguration();
 444 
 445                 // Platform loggers begin to delegate to java.util.logging.Logger
 446                 jdk.internal.logger.BootstrapLogger.redirectTemporaryLoggers();
 447 
 448             } catch (Exception ex) {
 449                 assert false : "Exception raised while reading logging configuration: " + ex;
 450             }
 451         }
 452     }
 453 
 454     // Returns the LoggerContext for the user code (i.e. application).




 455     private LoggerContext getUserContext() {
 456         return userContext;
























 457     }
 458 
 459     // The system context.
 460     final LoggerContext getSystemContext() {
 461         return systemContext;
 462     }
 463 
 464     private List<LoggerContext> contexts() {
 465         List<LoggerContext> cxs = new ArrayList<>();
 466         cxs.add(getSystemContext());
 467         cxs.add(getUserContext());
 468         return cxs;
 469     }
 470 
 471     // Find or create a specified logger instance. If a logger has
 472     // already been created with the given name it is returned.
 473     // Otherwise a new logger instance is created and registered
 474     // in the LogManager global namespace.
 475     // This method will always return a non-null Logger object.
 476     // Synchronization is not required here. All synchronization for


< prev index next >