< prev index next >

test/jdk/java/util/logging/LogManager/Configuration/rootLoggerHandlers/RootLoggerHandlers.java

Print this page
8196768: RootLoggerHandlers fails when source tree is read-only
Reviewed-by: dfuchs


  46 
  47     public static final Path SRC_DIR =
  48             Paths.get(System.getProperty("test.src", "src"));
  49     public static final Path USER_DIR =
  50             Paths.get(System.getProperty("user.dir", "."));
  51     public static final Path CONFIG_FILE = Paths.get("logging.properties");
  52 
  53     // Uncomment this to run the test on Java 8. Java 8 does not have
  54     // List.of(...)
  55     //    static final class List {
  56     //        static <T> java.util.List<T> of(T... items) {
  57     //            return Collections.unmodifiableList(Arrays.asList(items));
  58     //        }
  59     //    }
  60 
  61     public static void main(String[] args) throws IOException {
  62         Path initialProps = SRC_DIR.resolve(CONFIG_FILE);
  63         Path loggingProps = USER_DIR.resolve(CONFIG_FILE);
  64         System.setProperty("java.util.logging.config.file", loggingProps.toString());
  65         Files.copy(initialProps, loggingProps, StandardCopyOption.REPLACE_EXISTING);

  66         System.out.println("Root level is: " + Logger.getLogger("").getLevel());
  67         if (Logger.getLogger("").getLevel() != Level.INFO) {
  68             throw new RuntimeException("Expected root level INFO, got: "
  69                                         + Logger.getLogger("").getLevel());
  70         }
  71         // Verify that we have two handlers. One was configured with
  72         // handlers=custom.Handler, the other with
  73         // .handlers=custom.DotHandler
  74         // Verify that exactly one of the two handlers is a custom.Handler
  75         // Verify that exactly one of the two handlers is a custom.DotHandler
  76         // Verify that the two handlers has an id of '1'
  77         checkHandlers(Logger.getLogger(""),
  78                 Logger.getLogger("").getHandlers(),
  79                 1L,
  80                 custom.Handler.class,
  81                 custom.DotHandler.class);
  82         checkHandlers(Logger.getLogger("global"),
  83                 Logger.getGlobal().getHandlers(),
  84                 1L,
  85                 custom.GlobalHandler.class);




  46 
  47     public static final Path SRC_DIR =
  48             Paths.get(System.getProperty("test.src", "src"));
  49     public static final Path USER_DIR =
  50             Paths.get(System.getProperty("user.dir", "."));
  51     public static final Path CONFIG_FILE = Paths.get("logging.properties");
  52 
  53     // Uncomment this to run the test on Java 8. Java 8 does not have
  54     // List.of(...)
  55     //    static final class List {
  56     //        static <T> java.util.List<T> of(T... items) {
  57     //            return Collections.unmodifiableList(Arrays.asList(items));
  58     //        }
  59     //    }
  60 
  61     public static void main(String[] args) throws IOException {
  62         Path initialProps = SRC_DIR.resolve(CONFIG_FILE);
  63         Path loggingProps = USER_DIR.resolve(CONFIG_FILE);
  64         System.setProperty("java.util.logging.config.file", loggingProps.toString());
  65         Files.copy(initialProps, loggingProps, StandardCopyOption.REPLACE_EXISTING);
  66         loggingProps.toFile().setWritable(true);
  67         System.out.println("Root level is: " + Logger.getLogger("").getLevel());
  68         if (Logger.getLogger("").getLevel() != Level.INFO) {
  69             throw new RuntimeException("Expected root level INFO, got: "
  70                                         + Logger.getLogger("").getLevel());
  71         }
  72         // Verify that we have two handlers. One was configured with
  73         // handlers=custom.Handler, the other with
  74         // .handlers=custom.DotHandler
  75         // Verify that exactly one of the two handlers is a custom.Handler
  76         // Verify that exactly one of the two handlers is a custom.DotHandler
  77         // Verify that the two handlers has an id of '1'
  78         checkHandlers(Logger.getLogger(""),
  79                 Logger.getLogger("").getHandlers(),
  80                 1L,
  81                 custom.Handler.class,
  82                 custom.DotHandler.class);
  83         checkHandlers(Logger.getLogger("global"),
  84                 Logger.getGlobal().getHandlers(),
  85                 1L,
  86                 custom.GlobalHandler.class);


< prev index next >