< prev index next >

src/java.base/share/classes/jdk/internal/logger/DefaultLoggerFinder.java

Print this page


   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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


 120             Logger w = ref == null ? null :  ref.get();
 121             if (w == null) {
 122                 w = loggerSupplier.apply(name);
 123                 loggers.put(name, new WeakReference<>(w, queue));
 124             }
 125 
 126             // Remove stale mapping...
 127             Collection<Reference<Logger>> values = null;
 128             while ((ref = queue.poll()) != null) {
 129                 if (values == null) values = loggers.values();
 130                 values.remove(ref);
 131             }
 132             return w;
 133         }
 134 
 135         final static SharedLoggers system = new SharedLoggers();
 136         final static SharedLoggers application = new SharedLoggers();
 137     }
 138 
 139     public static boolean isSystem(Module m) {
 140         ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<>() {
 141             @Override
 142             public ClassLoader run() {
 143                 return m.getClassLoader();








 144             }
 145         });
 146         return cl == null;
 147     }
 148 
 149     @Override
 150     public final Logger getLogger(String name,  Module module) {
 151         checkPermission();
 152         return demandLoggerFor(name, module);
 153     }
 154 
 155     @Override
 156     public final Logger getLocalizedLogger(String name, ResourceBundle bundle,
 157                                            Module module) {
 158         return super.getLocalizedLogger(name, bundle, module);
 159     }
 160 
 161     /**
 162      * Returns a {@link Logger logger} suitable for use within the
 163      * given {@code module}.
 164      *
 165      * @implSpec The default implementation for this method is to return a
 166      *    simple logger that will print all messages of INFO level and above
   1 /*
   2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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


 120             Logger w = ref == null ? null :  ref.get();
 121             if (w == null) {
 122                 w = loggerSupplier.apply(name);
 123                 loggers.put(name, new WeakReference<>(w, queue));
 124             }
 125 
 126             // Remove stale mapping...
 127             Collection<Reference<Logger>> values = null;
 128             while ((ref = queue.poll()) != null) {
 129                 if (values == null) values = loggers.values();
 130                 values.remove(ref);
 131             }
 132             return w;
 133         }
 134 
 135         final static SharedLoggers system = new SharedLoggers();
 136         final static SharedLoggers application = new SharedLoggers();
 137     }
 138 
 139     public static boolean isSystem(Module m) {
 140         final boolean isSystem = AccessController.doPrivileged(new PrivilegedAction<>() {
 141             @Override
 142             public Boolean run() {
 143                 final ClassLoader moduleCL = m.getClassLoader();
 144                 if (moduleCL == null) return true;
 145                 ClassLoader cl = ClassLoader.getPlatformClassLoader();
 146                 while (cl != null && moduleCL != cl) {
 147                     cl = cl.getParent();
 148                 }
 149                 // returns true if moduleCL is the platform class loader
 150                 // or one of its ancestors.
 151                 return moduleCL == cl;
 152             }
 153         });
 154         return isSystem;
 155     }
 156 
 157     @Override
 158     public final Logger getLogger(String name,  Module module) {
 159         checkPermission();
 160         return demandLoggerFor(name, module);
 161     }
 162 
 163     @Override
 164     public final Logger getLocalizedLogger(String name, ResourceBundle bundle,
 165                                            Module module) {
 166         return super.getLocalizedLogger(name, bundle, module);
 167     }
 168 
 169     /**
 170      * Returns a {@link Logger logger} suitable for use within the
 171      * given {@code module}.
 172      *
 173      * @implSpec The default implementation for this method is to return a
 174      *    simple logger that will print all messages of INFO level and above
< prev index next >