Path: blob/master/src/java.base/share/classes/jdk/internal/logger/SurrogateLogger.java
41159 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.logger;2627import java.util.function.Function;28import sun.util.logging.PlatformLogger;2930/**31* A simple console logger used to emulate the behavior of JUL loggers when32* java.util.logging has no custom configuration.33* Surrogate loggers are usually only used temporarily, until the LogManager34* is initialized. At this point, the surrogates are replaced by an actual35* logger obtained from LogManager.36*/37public final class SurrogateLogger extends SimpleConsoleLogger {3839private static final PlatformLogger.Level JUL_DEFAULT_LEVEL =40PlatformLogger.Level.INFO;41private static volatile String simpleFormatString;4243SurrogateLogger(String name) {44super(name, true);45}4647@Override48PlatformLogger.Level defaultPlatformLevel() {49return JUL_DEFAULT_LEVEL;50}5152@Override53String getSimpleFormatString() {54if (simpleFormatString == null) {55simpleFormatString = getSimpleFormat(null);56}57return simpleFormatString;58}5960public static String getSimpleFormat(Function<String, String> defaultPropertyGetter) {61return Formatting.getSimpleFormat(Formatting.JUL_FORMAT_PROP_KEY, defaultPropertyGetter);62}6364public static SurrogateLogger makeSurrogateLogger(String name) {65return new SurrogateLogger(name);66}6768public static boolean isFilteredFrame(StackWalker.StackFrame st) {69return Formatting.isFilteredFrame(st);70}71}727374