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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 import java.io.IOException;
  24 import java.lang.System.Logger;
  25 import java.nio.file.Files;
  26 import java.nio.file.Path;
  27 import java.nio.file.Paths;
  28 import java.nio.file.StandardCopyOption;
  29 import java.util.ResourceBundle;
  30 
  31 /**
  32  *
  33  * @author danielfuchs
  34  */
  35 public final class AccessSystemLogger {
  36 
  37     public AccessSystemLogger() {
  38         this(check());
  39     }
  40 
  41     private AccessSystemLogger(Void unused) {
  42     }
  43 
  44     private static Void check() {
  45         if (AccessSystemLogger.class.getClassLoader() != null) {
  46             throw new RuntimeException("AccessSystemLogger should be loaded by the null classloader");
  47         }
  48         return null;
  49     }
  50 
  51     public Logger getLogger(String name) {
  52         Logger logger = System.getLogger(name);
  53         System.out.println("System.getLogger(\"" + name + "\"): " + logger);
  54         return logger;
  55     }
  56 
  57     public Logger getLogger(String name, ResourceBundle bundle) {
  58         Logger logger = System.getLogger(name, bundle);
  59         System.out.println("System.getLogger(\"" + name + "\", bundle): " + logger);
  60         return logger;
  61     }
  62 
  63     public java.util.logging.Logger demandSystemLogger(String name) {
  64         return java.util.logging.Logger.getLogger(name);
  65     }
  66 
  67     // copy AccessSystemLogger.class to ./boot
  68     public static void main(String[] args) throws IOException {
  69         Path testDir = Paths.get(System.getProperty("user.dir", "."));
  70         Path bootDir = Paths.get(testDir.toString(), "boot");
  71         Path classes = Paths.get(System.getProperty("test.classes", "build/classes"));
  72         Path thisClass = Paths.get(classes.toString(),
  73                 AccessSystemLogger.class.getSimpleName()+".class");
  74         if (Files.notExists(bootDir)) {
  75             Files.createDirectory(bootDir);
  76         }
  77         Path dest = Paths.get(bootDir.toString(),
  78                 AccessSystemLogger.class.getSimpleName()+".class");
  79         Files.copy(thisClass, dest, StandardCopyOption.REPLACE_EXISTING);
  80     }
  81 
  82 }