0N/A/*
2362N/A * Copyright (c) 2003, 2008, 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 com.sun.jmx.remote.util;
0N/A
0N/Aimport java.util.logging.Logger;
0N/A
0N/Apublic class ClassLogger {
0N/A
0N/A private static final boolean ok;
0N/A private final String className;
0N/A private final Logger logger;
0N/A
0N/A static {
0N/A /* We attempt to work even if we are running in J2SE 1.3, where
0N/A there is no java.util.logging. The technique we use here is
0N/A not strictly portable, but it does work with Sun's J2SE 1.3
0N/A at least. This is just a best effort: the Right Thing is for
0N/A people to use at least J2SE 1.4. */
0N/A boolean loaded = false;
0N/A try {
686N/A Class<?> c = java.util.logging.Logger.class;
0N/A loaded = true;
0N/A } catch (Error e) {
0N/A // OK.
0N/A // java.util.logger package is not available in this jvm.
0N/A }
0N/A ok = loaded;
0N/A }
0N/A
0N/A public ClassLogger(String subsystem, String className) {
0N/A if (ok)
0N/A logger = Logger.getLogger(subsystem);
0N/A else
0N/A logger = null;
0N/A this.className = className;
0N/A }
0N/A
0N/A public final boolean traceOn() {
0N/A return finerOn();
0N/A }
0N/A
0N/A public final boolean debugOn() {
0N/A return finestOn();
0N/A }
0N/A
0N/A public final boolean warningOn() {
0N/A return ok && logger.isLoggable(java.util.logging.Level.WARNING);
0N/A }
0N/A
0N/A public final boolean infoOn() {
0N/A return ok && logger.isLoggable(java.util.logging.Level.INFO);
0N/A }
0N/A
0N/A public final boolean configOn() {
0N/A return ok && logger.isLoggable(java.util.logging.Level.CONFIG);
0N/A }
0N/A
0N/A public final boolean fineOn() {
0N/A return ok && logger.isLoggable(java.util.logging.Level.FINE);
0N/A }
0N/A
0N/A public final boolean finerOn() {
0N/A return ok && logger.isLoggable(java.util.logging.Level.FINER);
0N/A }
0N/A
0N/A public final boolean finestOn() {
0N/A return ok && logger.isLoggable(java.util.logging.Level.FINEST);
0N/A }
0N/A
0N/A public final void debug(String func, String msg) {
0N/A finest(func,msg);
0N/A }
0N/A
0N/A public final void debug(String func, Throwable t) {
0N/A finest(func,t);
0N/A }
0N/A
0N/A public final void debug(String func, String msg, Throwable t) {
0N/A finest(func,msg,t);
0N/A }
0N/A
0N/A public final void trace(String func, String msg) {
0N/A finer(func,msg);
0N/A }
0N/A
0N/A public final void trace(String func, Throwable t) {
0N/A finer(func,t);
0N/A }
0N/A
0N/A public final void trace(String func, String msg, Throwable t) {
0N/A finer(func,msg,t);
0N/A }
0N/A
0N/A public final void error(String func, String msg) {
0N/A severe(func,msg);
0N/A }
0N/A
0N/A public final void error(String func, Throwable t) {
0N/A severe(func,t);
0N/A }
0N/A
0N/A public final void error(String func, String msg, Throwable t) {
0N/A severe(func,msg,t);
0N/A }
0N/A
0N/A public final void finest(String func, String msg) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINEST, className, func, msg);
0N/A }
0N/A
0N/A public final void finest(String func, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINEST, className, func,
0N/A t.toString(), t);
0N/A }
0N/A
0N/A public final void finest(String func, String msg, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINEST, className, func, msg,
0N/A t);
0N/A }
0N/A
0N/A public final void finer(String func, String msg) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINER, className, func, msg);
0N/A }
0N/A
0N/A public final void finer(String func, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINER, className, func,
0N/A t.toString(), t);
0N/A }
0N/A
0N/A public final void finer(String func, String msg, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINER, className, func, msg,t);
0N/A }
0N/A
0N/A public final void fine(String func, String msg) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINE, className, func, msg);
0N/A }
0N/A
0N/A public final void fine(String func, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINE, className, func,
0N/A t.toString(), t);
0N/A }
0N/A
0N/A public final void fine(String func, String msg, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.FINE, className, func, msg,
0N/A t);
0N/A }
0N/A
0N/A public final void config(String func, String msg) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.CONFIG, className, func, msg);
0N/A }
0N/A
0N/A public final void config(String func, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.CONFIG, className, func,
0N/A t.toString(), t);
0N/A }
0N/A
0N/A public final void config(String func, String msg, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.CONFIG, className, func, msg,
0N/A t);
0N/A }
0N/A
0N/A public final void info(String func, String msg) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.INFO, className, func, msg);
0N/A }
0N/A
0N/A public final void info(String func, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.INFO, className, func,
0N/A t.toString(), t);
0N/A }
0N/A
0N/A public final void info(String func, String msg, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.INFO, className, func, msg,
0N/A t);
0N/A }
0N/A
0N/A public final void warning(String func, String msg) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.WARNING, className, func, msg);
0N/A }
0N/A
0N/A public final void warning(String func, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.WARNING, className, func,
0N/A t.toString(), t);
0N/A }
0N/A
0N/A public final void warning(String func, String msg, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.WARNING, className, func, msg,
0N/A t);
0N/A }
0N/A
0N/A public final void severe(String func, String msg) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.SEVERE, className, func, msg);
0N/A }
0N/A
0N/A public final void severe(String func, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.SEVERE, className, func,
0N/A t.toString(), t);
0N/A }
0N/A
0N/A public final void severe(String func, String msg, Throwable t) {
0N/A if (ok)
0N/A logger.logp(java.util.logging.Level.SEVERE, className, func, msg,
0N/A t);
0N/A }
0N/A}