jdk/src/share/classes/sun/management/snmp/util/MibLogger.java
author mchung
Tue, 17 Jan 2012 15:55:40 -0800
changeset 11530 a9d059c15b80
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7117570: Warnings in sun.mangement.* and its subpackages Reviewed-by: mchung, dsamersoff Contributed-by: kurchi.subhra.hazra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.management.snmp.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.logging.Logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
public class MibLogger {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    final Logger logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    final String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    35
    static String getClassName(Class<?> clazz) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        if (clazz == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        if (clazz.isArray())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
            return getClassName(clazz.getComponentType()) + "[]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        final String fullname = clazz.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        final int lastpoint   = fullname.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        final int len         = fullname.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        if ((lastpoint < 0) || (lastpoint >= len))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            return fullname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        else return fullname.substring(lastpoint+1,len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    47
    static String getLoggerName(Class<?> clazz) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        if (clazz == null) return "sun.management.snmp.jvminstr";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        Package p = clazz.getPackage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        if (p == null) return "sun.management.snmp.jvminstr";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        final String pname = p.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        if (pname == null) return "sun.management.snmp.jvminstr";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        else return pname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    56
    public MibLogger(Class<?> clazz) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this(getLoggerName(clazz),getClassName(clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    60
    public MibLogger(Class<?> clazz, String postfix) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this(getLoggerName(clazz)+((postfix==null)?"":"."+postfix),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
             getClassName(clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public MibLogger(String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this("sun.management.snmp.jvminstr",className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public MibLogger(String loggerName, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        Logger l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            l = Logger.getLogger(loggerName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            // OK. Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        logger = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this.className=className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected Logger getLogger() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public boolean isTraceOn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (l==null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return l.isLoggable(Level.FINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public boolean isDebugOn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (l==null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return l.isLoggable(Level.FINEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public boolean isInfoOn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (l==null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return l.isLoggable(Level.INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public boolean isConfigOn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (l==null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return l.isLoggable(Level.CONFIG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public void config(String func, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (l!=null) l.logp(Level.CONFIG,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        func,msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void config(String func, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (l!=null) l.logp(Level.CONFIG,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        func,t.toString(),t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public void config(String func, String msg, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (l!=null) l.logp(Level.CONFIG,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        func,msg,t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void error(String func, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (l!=null) l.logp(Level.SEVERE,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        func,msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public void info(String func, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (l!=null) l.logp(Level.INFO,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                        func,msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void info(String func, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (l!=null) l.logp(Level.INFO,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                        func,t.toString(),t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void info(String func, String msg, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (l!=null) l.logp(Level.INFO,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        func,msg,t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void warning(String func, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (l!=null) l.logp(Level.WARNING,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                        func,msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void warning(String func, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (l!=null) l.logp(Level.WARNING,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        func,t.toString(),t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void warning(String func, String msg, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (l!=null) l.logp(Level.WARNING,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                        func,msg,t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public void trace(String func, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (l!=null) l.logp(Level.FINE,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                        func,msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void trace(String func, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (l!=null) l.logp(Level.FINE,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        func,t.toString(),t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public void trace(String func, String msg, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (l!=null) l.logp(Level.FINE,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        func,msg,t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public void debug(String func, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (l!=null) l.logp(Level.FINEST,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        func,msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void debug(String func, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (l!=null) l.logp(Level.FINEST,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                        func,t.toString(),t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public void debug(String func, String msg, Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        final Logger l = getLogger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (l!=null) l.logp(Level.FINEST,className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        func,msg,t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}