1 /* 2 * Copyright (c) 2009, 2014, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 27 package sun.util.logging; 28 29 import java.lang.System.Logger; 30 import java.util.ResourceBundle; 31 import java.util.function.Supplier; 32 import sun.util.logger.LoggerWrapper; 33 import sun.util.logging.PlatformLogger.Level; 34 35 /** 36 * Platform logger provides an API for the JRE components to log 37 * messages. 38 * 39 * The PlatformLoggerBridge interface is implemented by the System.Logger 40 * objects returned by our default JUL provider - so that JRE classes using 41 * PlatformLogger see no difference when JUL is the actual backend. 42 * 43 * The recommendation for JRE classes going forward is to use 44 * java.lang.System.getLogger(String name), which will 45 * use Lazy Loggers when possible and necessary. 46 * 47 * PlatformLogger is now only a thin adaptation layer over the same 48 * loggers than returned by java.lang.System.getLogger(String name). 49 * 50 * @since 1.9 51 */ 52 public interface PlatformLoggerBridge { 53 54 /** 55 * Gets the name for this platform logger. 56 * @return the name of the platform logger. 57 */ 58 public String getName(); 59 60 /** 61 * Returns true if a message of the given level would actually 62 * be logged by this logger. 63 * @param level the level 64 * @return whether a message of that level would be logged 65 */ 66 public boolean isLoggable(Level level); 67 public boolean isEnabled(); 68 69 public void log(Level level, String msg); 70 public void log(Level level, String msg, Throwable thrown); 71 public void log(Level level, String msg, Object... params); 72 public void log(Level level, Supplier<String> msgSupplier); 73 public void log(Level level, Throwable thrown, Supplier<String> msgSupplier); 74 public void logp(Level level, String sourceClass, String sourceMethod, String msg); 75 public void logp(Level level, String sourceClass, String sourceMethod, 76 Supplier<String> msgSupplier); 77 public void logp(Level level, String sourceClass, String sourceMethod, 78 String msg, Object... params); 79 public void logp(Level level, String sourceClass, String sourceMethod, 80 String msg, Throwable thrown); 81 public void logp(Level level, String sourceClass, String sourceMethod, 82 Throwable thrown, Supplier<String> msgSupplier); 83 public void logrb(Level level, String sourceClass, String sourceMethod, 84 ResourceBundle bundle, String msg, Object... params); 85 public void logrb(Level level, String sourceClass, String sourceMethod, 86 ResourceBundle bundle, String msg, Throwable thrown); 87 public void logrb(Level level, ResourceBundle bundle, String msg, 88 Object... params); 89 public void logrb(Level level, ResourceBundle bundle, String msg, 90 Throwable thrown); 91 92 93 public static PlatformLoggerBridge convert(Logger logger) { 94 if (logger instanceof PlatformLoggerBridge) { 95 return (PlatformLoggerBridge) logger; 96 } else { 97 return new LoggerWrapper<>(logger); 98 } 99 } 100 }