001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.log;
031:
032: import com.caucho.util.L10N;
033:
034: import java.util.logging.Handler;
035: import java.util.logging.LogRecord;
036:
037: /**
038: * Proxy for an underlying handler, e.g. to handle different
039: * logging levels.
040: */
041: public class SubHandler extends Handler {
042: private static final L10N L = new L10N(SubHandler.class);
043:
044: private Handler _handler;
045:
046: SubHandler(Handler handler) {
047: _handler = handler;
048: }
049:
050: /**
051: * Publishes the record.
052: */
053: public void publish(LogRecord record) {
054: if (record.getLevel().intValue() < getLevel().intValue())
055: return;
056:
057: if (_handler != null)
058: _handler.publish(record);
059: }
060:
061: /**
062: * Flushes the buffer.
063: */
064: public void flush() {
065: if (_handler != null)
066: _handler.flush();
067: }
068:
069: /**
070: * Closes the handler.
071: */
072: public void close() {
073: if (_handler != null)
074: _handler.close();
075:
076: _handler = null;
077: }
078:
079: /**
080: * Returns the hash code.
081: */
082: public int hashCode() {
083: if (_handler == null)
084: return super .hashCode();
085: else
086: return _handler.hashCode();
087: }
088:
089: /**
090: * Test for equality.
091: */
092: public boolean equals(Object o) {
093: if (this == o)
094: return true;
095: else if (o == null)
096: return false;
097:
098: if (_handler == null)
099: return false;
100: else if (o.equals(_handler))
101: return true;
102:
103: if (!(o instanceof SubHandler))
104: return false;
105:
106: SubHandler subHandler = (SubHandler) o;
107:
108: return _handler.equals(subHandler._handler);
109: }
110:
111: public String toString() {
112: return "SubHandler[" + _handler + "]";
113: }
114: }
|