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 package sun.rmi.runtime; 27 28 import java.io.ByteArrayOutputStream; 29 import java.io.IOException; 30 import java.io.PrintStream; 31 import java.io.OutputStream; 32 import java.rmi.server.LogStream; 33 import java.util.logging.ConsoleHandler; 34 import java.util.logging.Handler; 35 import java.util.logging.Formatter; 36 import java.util.logging.SimpleFormatter; 37 import java.util.logging.StreamHandler; 38 import java.util.logging.Level; 39 import java.util.logging.Logger; 40 import java.util.logging.LogManager; 41 import java.util.logging.LogRecord; 42 import java.util.logging.StreamHandler; 43 import java.util.Map; 44 import java.util.HashMap; 45 46 /** 47 * Utility which provides an abstract "logger" like RMI internal API 48 * which can be directed to use one of two types of logging 49 * infrastructure: the java.util.logging API or the 50 * java.rmi.server.LogStream API. The default behavior is to use the 51 * java.util.logging API. The LogStream API may be used instead by 52 * setting the system property sun.rmi.log.useOld to true. 53 * 54 * For backwards compatibility, supports the RMI system logging 55 * properties which pre-1.4 comprised the only way to configure RMI 56 * logging. If the java.util.logging API is used and RMI system log 57 * properties are set, the system properties override initial RMI 58 * logger values as appropriate. If the java.util.logging API is 59 * turned off, pre-1.4 logging behavior is used. 60 * 61 * @author Laird Dornin 62 * @since 1.4 63 */ 64 @SuppressWarnings("deprecation") 65 public abstract class Log { 66 67 /** Logger re-definition of old RMI log values */ 68 public static final Level BRIEF = Level.FINE; 69 public static final Level VERBOSE = Level.FINER; 70 71 /* selects log implementation */ 72 private static final LogFactory logFactory; 73 static { 74 boolean useOld = 75 Boolean.valueOf(java.security.AccessController. 76 doPrivileged(new sun.security.action.GetPropertyAction( 77 "sun.rmi.log.useOld"))).booleanValue(); 78 79 /* set factory to select the logging facility to use */ 80 logFactory = (useOld ? (LogFactory) new LogStreamLogFactory() : 81 (LogFactory) new LoggerLogFactory()); 82 } 83 84 /** "logger like" API to be used by RMI implementation */ 85 public abstract boolean isLoggable(Level level); 86 public abstract void log(Level level, String message); 87 public abstract void log(Level level, String message, Throwable thrown); 88 89 /** get and set the RMI server call output stream */ 90 public abstract void setOutputStream(OutputStream stream); 91 public abstract PrintStream getPrintStream(); 92 93 /** factory interface enables Logger and LogStream implementations */ 94 private static interface LogFactory { 95 Log createLog(String loggerName, String oldLogName, Level level); 96 } 97 | 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 package sun.rmi.runtime; 27 28 import java.io.ByteArrayOutputStream; 29 import java.io.PrintStream; 30 import java.io.OutputStream; 31 import java.rmi.server.LogStream; 32 import java.security.PrivilegedAction; 33 import java.util.logging.Handler; 34 import java.util.logging.SimpleFormatter; 35 import java.util.logging.Level; 36 import java.util.logging.Logger; 37 import java.util.logging.LogRecord; 38 import java.util.logging.StreamHandler; 39 40 /** 41 * Utility which provides an abstract "logger" like RMI internal API 42 * which can be directed to use one of two types of logging 43 * infrastructure: the java.util.logging API or the 44 * java.rmi.server.LogStream API. The default behavior is to use the 45 * java.util.logging API. The LogStream API may be used instead by 46 * setting the system property sun.rmi.log.useOld to true. 47 * 48 * For backwards compatibility, supports the RMI system logging 49 * properties which pre-1.4 comprised the only way to configure RMI 50 * logging. If the java.util.logging API is used and RMI system log 51 * properties are set, the system properties override initial RMI 52 * logger values as appropriate. If the java.util.logging API is 53 * turned off, pre-1.4 logging behavior is used. 54 * 55 * @author Laird Dornin 56 * @since 1.4 57 */ 58 @SuppressWarnings("deprecation") 59 public abstract class Log { 60 61 /** Logger re-definition of old RMI log values */ 62 public static final Level BRIEF = Level.FINE; 63 public static final Level VERBOSE = Level.FINER; 64 65 /* selects log implementation */ 66 private static final LogFactory logFactory; 67 static { 68 boolean useOld = java.security.AccessController.doPrivileged( 69 (PrivilegedAction<Boolean>) () -> Boolean.getBoolean("sun.rmi.log.useOld")); 70 71 /* set factory to select the logging facility to use */ 72 logFactory = (useOld ? (LogFactory) new LogStreamLogFactory() : 73 (LogFactory) new LoggerLogFactory()); 74 } 75 76 /** "logger like" API to be used by RMI implementation */ 77 public abstract boolean isLoggable(Level level); 78 public abstract void log(Level level, String message); 79 public abstract void log(Level level, String message, Throwable thrown); 80 81 /** get and set the RMI server call output stream */ 82 public abstract void setOutputStream(OutputStream stream); 83 public abstract PrintStream getPrintStream(); 84 85 /** factory interface enables Logger and LogStream implementations */ 86 private static interface LogFactory { 87 Log createLog(String loggerName, String oldLogName, Level level); 88 } 89 |