1 /* |
1 /* |
2 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
394 owner.readPrimordialConfiguration(); |
394 owner.readPrimordialConfiguration(); |
395 |
395 |
396 // Create and retain Logger for the root of the namespace. |
396 // Create and retain Logger for the root of the namespace. |
397 owner.addLogger(root); |
397 owner.addLogger(root); |
398 |
398 |
399 // For backward compatibility: add any handlers configured using |
|
400 // ".handlers" |
|
401 owner.createLoggerHandlers("", ".handlers") |
|
402 .stream() |
|
403 .forEach(root::addHandler); |
|
404 |
|
405 // Initialize level if not yet initialized |
399 // Initialize level if not yet initialized |
406 if (!root.isLevelInitialized()) { |
400 if (!root.isLevelInitialized()) { |
407 root.setLevel(defaultLevel); |
401 root.setLevel(defaultLevel); |
408 } |
402 } |
409 |
403 |
993 closeOnResetLoggers.addIfAbsent(CloseOnReset.create(logger)); |
987 closeOnResetLoggers.addIfAbsent(CloseOnReset.create(logger)); |
994 } |
988 } |
995 } |
989 } |
996 } |
990 } |
997 |
991 |
998 private List<Handler> createLoggerHandlers(final String name, final String handlersPropertyName) |
992 private List<Handler> createLoggerHandlers(final String name, |
|
993 final String handlersPropertyName) |
999 { |
994 { |
1000 String names[] = parseClassNames(handlersPropertyName); |
995 String names[] = parseClassNames(handlersPropertyName); |
1001 List<Handler> handlers = new ArrayList<>(names.length); |
996 List<Handler> handlers = new ArrayList<>(names.length); |
1002 for (String type : names) { |
997 for (String type : names) { |
1003 try { |
998 try { |
1196 if (name == null) { |
1191 if (name == null) { |
1197 throw new NullPointerException(); |
1192 throw new NullPointerException(); |
1198 } |
1193 } |
1199 drainLoggerRefQueueBounded(); |
1194 drainLoggerRefQueueBounded(); |
1200 LoggerContext cx = getUserContext(); |
1195 LoggerContext cx = getUserContext(); |
1201 if (cx.addLocalLogger(logger)) { |
1196 if (cx.addLocalLogger(logger) || forceLoadHandlers(logger)) { |
1202 // Do we have a per logger handler too? |
1197 // Do we have a per logger handler too? |
1203 // Note: this will add a 200ms penalty |
1198 // Note: this will add a 200ms penalty |
1204 loadLoggerHandlers(logger, name, name + ".handlers"); |
1199 loadLoggerHandlers(logger, name, name + ".handlers"); |
1205 return true; |
1200 return true; |
1206 } else { |
1201 } else { |
1207 return false; |
1202 return false; |
1208 } |
1203 } |
|
1204 } |
|
1205 |
|
1206 |
|
1207 // Checks whether the given logger is a special logger |
|
1208 // that still requires handler initialization. |
|
1209 // This method will only return true for the root and |
|
1210 // global loggers and only if called by the thread that |
|
1211 // performs initialization of the LogManager, during that |
|
1212 // initialization. Must only be called by addLogger. |
|
1213 @SuppressWarnings("deprecation") |
|
1214 private boolean forceLoadHandlers(Logger logger) { |
|
1215 // Called just after reading the primordial configuration, in |
|
1216 // the same thread that reads it. |
|
1217 // The root and global logger would already be present in the context |
|
1218 // by this point, but we would not have called loadLoggerHandlers |
|
1219 // yet. |
|
1220 return (logger == rootLogger || logger == Logger.global) |
|
1221 && !initializationDone |
|
1222 && initializedCalled |
|
1223 && configurationLock.isHeldByCurrentThread(); |
1209 } |
1224 } |
1210 |
1225 |
1211 // Private method to set a level on a logger. |
1226 // Private method to set a level on a logger. |
1212 // If necessary, we raise privilege before doing the call. |
1227 // If necessary, we raise privilege before doing the call. |
1213 private static void doSetLevel(final Logger logger, final Level level) { |
1228 private static void doSetLevel(final Logger logger, final Level level) { |