1 /* 2 * To change this license header, choose License Headers in Project Properties. 3 * To change this template file, choose Tools | Templates 4 * and open the template in the editor. 5 /* 6 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8 * 9 * This code is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU General Public License version 2 only, as 11 * published by the Free Software Foundation. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24 * or visit www.oracle.com if you need additional information or have any 25 * questions. 26 */ 27 import java.io.IOException; 28 import java.lang.System.Logger; 29 import java.nio.file.Files; 30 import java.nio.file.Path; 31 import java.nio.file.Paths; 32 import java.nio.file.StandardCopyOption; 33 import java.util.ResourceBundle; 34 35 /** 36 * 37 * @author danielfuchs 38 */ 39 public final class AccessSystemLogger { 40 41 public AccessSystemLogger() { 42 this(check()); 43 } 44 45 private AccessSystemLogger(Void unused) { 46 } 47 48 private static Void check() { 49 if (AccessSystemLogger.class.getClassLoader() != null) { 50 throw new RuntimeException("AccessSystemLogger should be loaded by the null classloader"); 51 } 52 return null; 53 } 54 55 public Logger getLogger(String name) { 56 Logger logger = System.getLogger(name); 57 System.out.println("System.getLogger(\"" + name + "\"): " + logger); 58 return logger; 59 } 60 61 public Logger getLogger(String name, ResourceBundle bundle) { 62 Logger logger = System.getLogger(name, bundle); 63 System.out.println("System.getLogger(\"" + name + "\", bundle): " + logger); 64 return logger; 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 }