< prev index next >

src/java.base/share/classes/sun/util/logging/PlatformLogger.java

Print this page




 269         }
 270     }
 271 
 272     // Table of known loggers.  Maps names to PlatformLoggers.
 273     private static final Map<String,WeakReference<PlatformLogger>> loggers =
 274         new HashMap<>();
 275 
 276     /**
 277      * Returns a PlatformLogger of a given name.
 278      * @param name the name of the logger
 279      * @return a PlatformLogger
 280      */
 281     public static synchronized PlatformLogger getLogger(String name) {
 282         PlatformLogger log = null;
 283         WeakReference<PlatformLogger> ref = loggers.get(name);
 284         if (ref != null) {
 285             log = ref.get();
 286         }
 287         if (log == null) {
 288             log = new PlatformLogger(PlatformLogger.Bridge.convert(
 289                     // We pass PlatformLogger.class rather than the actual caller

 290                     // because we want PlatformLoggers to be system loggers: we
 291                     // won't need to resolve any resource bundles anyway.
 292                     // Note: Many unit tests depend on the fact that
 293                     //       PlatformLogger.getLoggerFromFinder is not caller sensitive.
 294                     LazyLoggers.getLazyLogger(name, PlatformLogger.class)));


 295             loggers.put(name, new WeakReference<>(log));
 296         }
 297         return log;
 298     }
 299 
 300     // The system loggerProxy returned by LazyLoggers
 301     // This may be a lazy logger - see jdk.internal.logger.LazyLoggers,
 302     // or may be a Logger instance (or a wrapper thereof).
 303     //
 304     private final PlatformLogger.Bridge loggerProxy;
 305     private PlatformLogger(PlatformLogger.Bridge loggerProxy) {
 306         this.loggerProxy = loggerProxy;
 307     }
 308 
 309     /**
 310      * A convenience method to test if the logger is turned off.
 311      * (i.e. its level is OFF).
 312      * @return whether the logger is turned off.
 313      */
 314     public boolean isEnabled() {




 269         }
 270     }
 271 
 272     // Table of known loggers.  Maps names to PlatformLoggers.
 273     private static final Map<String,WeakReference<PlatformLogger>> loggers =
 274         new HashMap<>();
 275 
 276     /**
 277      * Returns a PlatformLogger of a given name.
 278      * @param name the name of the logger
 279      * @return a PlatformLogger
 280      */
 281     public static synchronized PlatformLogger getLogger(String name) {
 282         PlatformLogger log = null;
 283         WeakReference<PlatformLogger> ref = loggers.get(name);
 284         if (ref != null) {
 285             log = ref.get();
 286         }
 287         if (log == null) {
 288             log = new PlatformLogger(PlatformLogger.Bridge.convert(
 289                     // We pass PlatformLogger.class.getModule() (java.base)
 290                     // rather than the actual module of the caller
 291                     // because we want PlatformLoggers to be system loggers: we
 292                     // won't need to resolve any resource bundles anyway.
 293                     // Note: Many unit tests depend on the fact that
 294                     //       PlatformLogger.getLoggerFromFinder is not caller
 295                     //       sensitive, and this strategy ensure that the tests
 296                     //       still pass.
 297                     LazyLoggers.getLazyLogger(name, PlatformLogger.class.getModule())));
 298             loggers.put(name, new WeakReference<>(log));
 299         }
 300         return log;
 301     }
 302 
 303     // The system loggerProxy returned by LazyLoggers
 304     // This may be a lazy logger - see jdk.internal.logger.LazyLoggers,
 305     // or may be a Logger instance (or a wrapper thereof).
 306     //
 307     private final PlatformLogger.Bridge loggerProxy;
 308     private PlatformLogger(PlatformLogger.Bridge loggerProxy) {
 309         this.loggerProxy = loggerProxy;
 310     }
 311 
 312     /**
 313      * A convenience method to test if the logger is turned off.
 314      * (i.e. its level is OFF).
 315      * @return whether the logger is turned off.
 316      */
 317     public boolean isEnabled() {


< prev index next >