001: /*
002: * The contents of this file are subject to the Mozilla Public License
003: * Version 1.1 (the "License"); you may not use this file except in
004: * compliance with the License. You may obtain a copy of the License at
005: * http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009: * License for the specific language governing rights and limitations
010: * under the License.
011: *
012: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013: *
014: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016: *
017: * Contributor(s):
018: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019: *
020: * If you didn't download this code from the following link, you should check
021: * if you aren't using an obsolete version: http://www.isqlviewer.com
022: */
023: package org.isqlviewer.util;
024:
025: import org.apache.log4j.Logger;
026:
027: /**
028: * Utility base class for providing logging support as part of the class itself.
029: * <p>
030: * Point of this is simple; and that is to make logging information via log4j easier
031: *
032: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
033: * @version 1.0
034: */
035: public abstract class LoggableObject {
036:
037: private Logger logger = Logger.getLogger(getClass());
038:
039: /**
040: * Logs informational error and supplementary message.
041: * <p>
042: * if informational messages are enabled the message and exception will be logged to designated destination.
043: *
044: * @param message informational message to log.
045: * @param error exception associated with the message.
046: */
047: protected final void info(Object message, Throwable error) {
048:
049: if (logger.isInfoEnabled()) {
050: logger.info(message, error);
051: }
052: }
053:
054: /**
055: * Logs an informational message.
056: * <p>
057: * if informational loggins is enabled the message will be logged to designated destination.
058: *
059: * @param message informational message to log.
060: */
061: protected final void info(Object message) {
062:
063: if (logger.isInfoEnabled()) {
064: logger.info(message);
065: }
066: }
067:
068: /**
069: * Logs debugging messages and supplementary exception.
070: * <p>
071: * if debug messages are enabled the message and exception will be logged to designated destination.
072: *
073: * @param message debug message to log.
074: * @param error exception associated with the message.
075: */
076: protected final void debug(Object message, Throwable error) {
077:
078: if (logger.isDebugEnabled()) {
079: logger.debug(message, error);
080: }
081: }
082:
083: /**
084: * Logs message for debugging purposes.
085: * <p>
086: * if debugging is enabled the message will be logged to designated destination.
087: *
088: * @param message debug information to log.
089: */
090: protected final void debug(Object message) {
091:
092: if (logger.isDebugEnabled()) {
093: logger.debug(message);
094: }
095: }
096:
097: /**
098: * Logs error messages and supplementary exception.
099: * <p>
100: * if error messages are enabled the message and exception will be logged to designated destination.
101: *
102: * @param message error message to log.
103: * @param error exception associated with the message.
104: */
105: protected final void error(Object message, Throwable error) {
106:
107: logger.error(message, error);
108: }
109:
110: /**
111: * Logs an error message.
112: * <p>
113: * if error logging is enabled the message will be logged to designated destination.
114: *
115: * @param message error message to log.
116: */
117: protected final void error(Object message) {
118:
119: logger.error(message);
120: }
121:
122: /**
123: * Logs warning messages and supplementary exception.
124: * <p>
125: *
126: * @param message warning message to log.
127: * @param error exception associated with the message.
128: */
129: protected final void warn(Object message, Throwable error) {
130:
131: logger.warn(message, error);
132: }
133:
134: /**
135: * Logs warning messages.
136: * <p>
137: *
138: * @param message warning information to log.
139: */
140: protected final void warn(Object message) {
141:
142: logger.warn(message);
143: }
144:
145: }
|