1 /* 2 * Copyright (c) 2009, 2013, 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 package java.util.logging; 27 28 import sun.util.logging.LoggingProxy; 29 30 /** 31 * Implementation of LoggingProxy when java.util.logging classes exist. 32 */ 33 class LoggingProxyImpl implements LoggingProxy { 34 static final LoggingProxy INSTANCE = new LoggingProxyImpl(); 35 LoggingProxyImpl()36 private LoggingProxyImpl() { } 37 38 @Override getLogger(String name)39 public Object getLogger(String name) { 40 // always create a platform logger with the resource bundle name 41 return Logger.getPlatformLogger(name); 42 } 43 44 @Override getLevel(Object logger)45 public Object getLevel(Object logger) { 46 return ((Logger) logger).getLevel(); 47 } 48 49 @Override setLevel(Object logger, Object newLevel)50 public void setLevel(Object logger, Object newLevel) { 51 ((Logger) logger).setLevel((Level) newLevel); 52 } 53 54 @Override isLoggable(Object logger, Object level)55 public boolean isLoggable(Object logger, Object level) { 56 return ((Logger) logger).isLoggable((Level) level); 57 } 58 59 @Override log(Object logger, Object level, String msg)60 public void log(Object logger, Object level, String msg) { 61 ((Logger) logger).log((Level) level, msg); 62 } 63 64 @Override log(Object logger, Object level, String msg, Throwable t)65 public void log(Object logger, Object level, String msg, Throwable t) { 66 ((Logger) logger).log((Level) level, msg, t); 67 } 68 69 @Override log(Object logger, Object level, String msg, Object... params)70 public void log(Object logger, Object level, String msg, Object... params) { 71 ((Logger) logger).log((Level) level, msg, params); 72 } 73 74 @Override getLoggerNames()75 public java.util.List<String> getLoggerNames() { 76 return LogManager.getLoggingMXBean().getLoggerNames(); 77 } 78 79 @Override getLoggerLevel(String loggerName)80 public String getLoggerLevel(String loggerName) { 81 return LogManager.getLoggingMXBean().getLoggerLevel(loggerName); 82 } 83 84 @Override setLoggerLevel(String loggerName, String levelName)85 public void setLoggerLevel(String loggerName, String levelName) { 86 LogManager.getLoggingMXBean().setLoggerLevel(loggerName, levelName); 87 } 88 89 @Override getParentLoggerName(String loggerName)90 public String getParentLoggerName(String loggerName) { 91 return LogManager.getLoggingMXBean().getParentLoggerName(loggerName); 92 } 93 94 @Override parseLevel(String levelName)95 public Object parseLevel(String levelName) { 96 Level level = Level.findLevel(levelName); 97 if (level == null) { 98 throw new IllegalArgumentException("Unknown level \"" + levelName + "\""); 99 } 100 return level; 101 } 102 103 @Override getLevelName(Object level)104 public String getLevelName(Object level) { 105 return ((Level) level).getLevelName(); 106 } 107 108 @Override getLevelValue(Object level)109 public int getLevelValue(Object level) { 110 return ((Level) level).intValue(); 111 } 112 113 @Override getProperty(String key)114 public String getProperty(String key) { 115 return LogManager.getLogManager().getProperty(key); 116 } 117 } 118