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 
AccessSystemLogger()37     public AccessSystemLogger() {
38         this(check());
39     }
40 
AccessSystemLogger(Void unused)41     private AccessSystemLogger(Void unused) {
42     }
43 
check()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 
getLogger(String name)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 
getLogger(String name, ResourceBundle bundle)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     // copy AccessSystemLogger.class to ./boot
main(String[] args)64     public static void main(String[] args) throws IOException {
65         Path testDir = Paths.get(System.getProperty("user.dir", "."));
66         Path bootDir = Paths.get(testDir.toString(), "boot");
67         Path classes = Paths.get(System.getProperty("test.classes", "build/classes"));
68         Path thisClass = Paths.get(classes.toString(),
69                 AccessSystemLogger.class.getSimpleName()+".class");
70         if (Files.notExists(bootDir)) {
71             Files.createDirectory(bootDir);
72         }
73         Path dest = Paths.get(bootDir.toString(),
74                 AccessSystemLogger.class.getSimpleName()+".class");
75         Files.copy(thisClass, dest, StandardCopyOption.REPLACE_EXISTING);
76     }
77 
78 }
79