/* * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// ## The LogManager.demandLogger method does not handle custom log manager // ## that overrides the getLogger method to return a custom logger // ## (see the test case in 8005640). Logger.getLogger may return // ## a Logger instance but LogManager overrides it with a custom Logger // ## instance like this case. // // However, the specification of LogManager and Logger subclassing is // not clear whether this is supported or not. The following check // just captures the current behavior. if (logger instanceof CustomLogger) { thrownew RuntimeException(logger + " not CustomLogger");
}
}
/* * This SimpleLogManager overrides the addLogger method to replace * the given logger with a custom logger. * * It's unclear what the recommended way to use custom logger is. * A LogManager subclass might override the getLogger method to return * a custom Logger and create a new custom logger if not exist so that * Logger.getLogger() can return a custom Logger instance but that violates * the LogManager.getLogger() spec which should return null if not found.
*/ publicsynchronizedboolean addLogger(Logger logger) {
String name = logger.getName(); if (namedLoggers.containsKey(name)) { returnfalse;
}
CustomLogger newLogger = new CustomLogger(logger); returnsuper.addLogger(newLogger);
}
publicclass CustomLogger extends Logger { final Logger keepRef; // keep a strong reference to avoid GC.
CustomLogger(Logger logger) { super(logger.getName(), logger.getResourceBundleName());
keepRef = logger;
}
}
}
¤ Dauer der Verarbeitung: 0.21 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.