0N/A/*
2362N/A * Copyright (c) 2003, 2004, 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/Apackage sun.management.snmp.util;
0N/A
0N/Aimport java.util.logging.Logger;
0N/Aimport java.util.logging.Level;
0N/A
0N/Apublic class MibLogger {
0N/A
0N/A final Logger logger;
0N/A final String className;
0N/A
0N/A static String getClassName(Class clazz) {
0N/A if (clazz == null) return null;
0N/A if (clazz.isArray())
0N/A return getClassName(clazz.getComponentType()) + "[]";
0N/A final String fullname = clazz.getName();
0N/A final int lastpoint = fullname.lastIndexOf('.');
0N/A final int len = fullname.length();
0N/A if ((lastpoint < 0) || (lastpoint >= len))
0N/A return fullname;
0N/A else return fullname.substring(lastpoint+1,len);
0N/A }
0N/A
0N/A static String getLoggerName(Class clazz) {
0N/A if (clazz == null) return "sun.management.snmp.jvminstr";
0N/A Package p = clazz.getPackage();
0N/A if (p == null) return "sun.management.snmp.jvminstr";
0N/A final String pname = p.getName();
0N/A if (pname == null) return "sun.management.snmp.jvminstr";
0N/A else return pname;
0N/A }
0N/A
0N/A public MibLogger(Class clazz) {
0N/A this(getLoggerName(clazz),getClassName(clazz));
0N/A }
0N/A
0N/A public MibLogger(Class clazz, String postfix) {
0N/A this(getLoggerName(clazz)+((postfix==null)?"":"."+postfix),
0N/A getClassName(clazz));
0N/A }
0N/A
0N/A public MibLogger(String className) {
0N/A this("sun.management.snmp.jvminstr",className);
0N/A }
0N/A
0N/A public MibLogger(String loggerName, String className) {
0N/A Logger l = null;
0N/A try {
0N/A l = Logger.getLogger(loggerName);
0N/A } catch (Exception x) {
0N/A // OK. Should not happen
0N/A }
0N/A logger = l;
0N/A this.className=className;
0N/A }
0N/A
0N/A protected Logger getLogger() {
0N/A return logger;
0N/A }
0N/A
0N/A public boolean isTraceOn() {
0N/A final Logger l = getLogger();
0N/A if (l==null) return false;
0N/A return l.isLoggable(Level.FINE);
0N/A }
0N/A
0N/A public boolean isDebugOn() {
0N/A final Logger l = getLogger();
0N/A if (l==null) return false;
0N/A return l.isLoggable(Level.FINEST);
0N/A }
0N/A
0N/A public boolean isInfoOn() {
0N/A final Logger l = getLogger();
0N/A if (l==null) return false;
0N/A return l.isLoggable(Level.INFO);
0N/A }
0N/A
0N/A public boolean isConfigOn() {
0N/A final Logger l = getLogger();
0N/A if (l==null) return false;
0N/A return l.isLoggable(Level.CONFIG);
0N/A }
0N/A
0N/A public void config(String func, String msg) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.CONFIG,className,
0N/A func,msg);
0N/A }
0N/A
0N/A public void config(String func, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.CONFIG,className,
0N/A func,t.toString(),t);
0N/A }
0N/A
0N/A public void config(String func, String msg, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.CONFIG,className,
0N/A func,msg,t);
0N/A }
0N/A
0N/A public void error(String func, String msg) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.SEVERE,className,
0N/A func,msg);
0N/A }
0N/A
0N/A public void info(String func, String msg) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.INFO,className,
0N/A func,msg);
0N/A }
0N/A
0N/A public void info(String func, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.INFO,className,
0N/A func,t.toString(),t);
0N/A }
0N/A
0N/A public void info(String func, String msg, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.INFO,className,
0N/A func,msg,t);
0N/A }
0N/A
0N/A public void warning(String func, String msg) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.WARNING,className,
0N/A func,msg);
0N/A }
0N/A
0N/A public void warning(String func, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.WARNING,className,
0N/A func,t.toString(),t);
0N/A }
0N/A
0N/A public void warning(String func, String msg, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.WARNING,className,
0N/A func,msg,t);
0N/A }
0N/A
0N/A public void trace(String func, String msg) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.FINE,className,
0N/A func,msg);
0N/A }
0N/A
0N/A public void trace(String func, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.FINE,className,
0N/A func,t.toString(),t);
0N/A }
0N/A
0N/A public void trace(String func, String msg, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.FINE,className,
0N/A func,msg,t);
0N/A }
0N/A
0N/A public void debug(String func, String msg) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.FINEST,className,
0N/A func,msg);
0N/A }
0N/A
0N/A public void debug(String func, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.FINEST,className,
0N/A func,t.toString(),t);
0N/A }
0N/A
0N/A public void debug(String func, String msg, Throwable t) {
0N/A final Logger l = getLogger();
0N/A if (l!=null) l.logp(Level.FINEST,className,
0N/A func,msg,t);
0N/A }
0N/A}