001: /**
002: * $Id: DebugHandler.java,v 1.1 2004/01/21 20:41:41 sathyakn Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */
014:
015: /**
016: * This class provides a bridge between the JDK 1.4 logging API and the
017: * Identity Server Debug API.
018: *
019: * @see java.util.logging
020: * @see com.iplanet.am.util.Debug
021: */package com.sun.mobile.cdm;
022:
023: import java.util.logging.Handler;
024: import java.util.logging.Level;
025: import java.util.logging.LogRecord;
026:
027: import com.iplanet.am.util.Debug;
028:
029: public class DebugHandler extends Handler {
030:
031: private Debug debug = null;
032:
033: /**
034: * Creates a <code>DebugHandler</code> object that uses the specified
035: * <code>Debug</code> object to record messages.
036: *
037: * @param debug the <code>Debug</code> object to use to record messages.
038: */
039: public DebugHandler(Debug debug) {
040: super ();
041: this .debug = debug;
042: }
043:
044: /**
045: * Does nothing.
046: */
047: public void close() throws SecurityException {
048: }
049:
050: /**
051: * Does nothing.
052: */
053: public void flush() {
054: }
055:
056: /**
057: * Publishes the specified <code>LogRecord</code> object using the
058: * <code>Debug</code> object used to create this object. The following
059: * table summarizes the mapping between <code>LogRecord</code> levels and
060: * <code>Debug</code> levels:
061: *
062: * <table>
063: * <tr>
064: * <th>LogRecord</th>
065: * <th>Debug</th>
066: * </tr>
067: * <tr>
068: * <td>SEVERE</td>
069: * <td>ERROR</td>
070: * </tr>
071: * <tr>
072: * <td>WARNING</td>
073: * <td>WARNING</td>
074: * </tr>
075: * <tr>
076: * <td>anything else</td>
077: * <td>MESSAGE</td>
078: * </tr>
079: * </table>
080: *
081: * @param record the <code>LogRecord</code> object to publish
082: * @throws NullPointerException if this object was created with a null
083: * <code>Debug</code> object
084: */
085: public void publish(LogRecord record) {
086: Level level = record.getLevel();
087: String className = record.getSourceClassName();
088: String methodName = record.getSourceMethodName();
089: String message = className + " " + methodName + " "
090: + record.getMessage();
091: if (level.equals(Level.SEVERE)) {
092: debug.error(message);
093: } else if (level.equals(Level.WARNING)) {
094: debug.warning(message);
095: } else {
096: debug.message(message);
097: }
098: }
099:
100: }
|