0N/A/*
3909N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.util.logging;
0N/A
0N/Aimport java.util.Enumeration;
0N/Aimport java.util.List;
0N/Aimport java.util.ArrayList;
0N/A
0N/A/**
0N/A * Logging is the implementation class of LoggingMXBean.
0N/A *
0N/A * The <tt>LoggingMXBean</tt> interface provides a standard
0N/A * method for management access to the individual
5720N/A * {@code Logger} objects available at runtime.
0N/A *
0N/A * @author Ron Mann
0N/A * @author Mandy Chung
0N/A * @since 1.5
0N/A *
0N/A * @see javax.management
5720N/A * @see Logger
5720N/A * @see LogManager
0N/A */
0N/Aclass Logging implements LoggingMXBean {
0N/A
0N/A private static LogManager logManager = LogManager.getLogManager();
0N/A
0N/A /** Constructor of Logging which is the implementation class
0N/A * of LoggingMXBean.
0N/A */
0N/A Logging() {
0N/A }
0N/A
0N/A public List<String> getLoggerNames() {
0N/A Enumeration loggers = logManager.getLoggerNames();
3323N/A ArrayList<String> array = new ArrayList<>();
0N/A
0N/A for (; loggers.hasMoreElements();) {
0N/A array.add((String) loggers.nextElement());
0N/A }
0N/A return array;
0N/A }
0N/A
0N/A private static String EMPTY_STRING = "";
0N/A public String getLoggerLevel(String loggerName) {
0N/A Logger l = logManager.getLogger(loggerName);
0N/A if (l == null) {
0N/A return null;
0N/A }
0N/A
0N/A Level level = l.getLevel();
0N/A if (level == null) {
0N/A return EMPTY_STRING;
0N/A } else {
5720N/A return level.getLevelName();
0N/A }
0N/A }
0N/A
0N/A public void setLoggerLevel(String loggerName, String levelName) {
0N/A if (loggerName == null) {
0N/A throw new NullPointerException("loggerName is null");
0N/A }
0N/A
0N/A Logger logger = logManager.getLogger(loggerName);
0N/A if (logger == null) {
0N/A throw new IllegalArgumentException("Logger " + loggerName +
0N/A "does not exist");
0N/A }
0N/A
0N/A Level level = null;
0N/A if (levelName != null) {
0N/A // parse will throw IAE if logLevel is invalid
5720N/A level = Level.findLevel(levelName);
5720N/A if (level == null) {
5720N/A throw new IllegalArgumentException("Unknown level \"" + levelName + "\"");
5720N/A }
0N/A }
0N/A
0N/A logger.setLevel(level);
0N/A }
0N/A
0N/A public String getParentLoggerName( String loggerName ) {
0N/A Logger l = logManager.getLogger( loggerName );
0N/A if (l == null) {
0N/A return null;
0N/A }
0N/A
0N/A Logger p = l.getParent();
0N/A if (p == null) {
0N/A // root logger
0N/A return EMPTY_STRING;
0N/A } else {
0N/A return p.getName();
0N/A }
0N/A }
0N/A}