001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.log.impl;
010:
011: import com.completex.objective.components.log.Log;
012: import com.completex.objective.components.log.LogConsts;
013:
014: import java.io.PrintStream;
015:
016: /**
017: * Primitive log implementation that prints the messages to the PrintStream
018: * provided as a constructor argument
019: * @see Log
020: *
021: * @author Gennady Krizhevsky
022: */
023: public abstract class PrimitiveLogImpl implements Log, LogConsts {
024:
025: private boolean traceEnabled = false;
026: private boolean debugEnabled = true;
027: private boolean infoEnabled = true;
028: private boolean warnEnabled = true;
029: private boolean errorEnabled = true;
030: private boolean fatalEnabled = true;
031: private PrintStream printStream;
032:
033: /**
034: * @param printStream - stream to print out messages
035: */
036: protected PrimitiveLogImpl(PrintStream printStream) {
037: this .printStream = printStream;
038: }
039:
040: public boolean isTraceEnabled() {
041: return traceEnabled;
042: }
043:
044: public void setTraceEnabled(boolean traceEnabled) {
045: this .traceEnabled = traceEnabled;
046: }
047:
048: public boolean isDebugEnabled() {
049: return debugEnabled;
050: }
051:
052: public void setDebugEnabled(boolean debugEnabled) {
053: this .debugEnabled = debugEnabled;
054: }
055:
056: public boolean isInfoEnabled() {
057: return infoEnabled;
058: }
059:
060: public void setInfoEnabled(boolean infoEnabled) {
061: this .infoEnabled = infoEnabled;
062: }
063:
064: public boolean isWarnEnabled() {
065: return warnEnabled;
066: }
067:
068: public void setWarnEnabled(boolean warnEnabled) {
069: this .warnEnabled = warnEnabled;
070: }
071:
072: public boolean isErrorEnabled() {
073: return errorEnabled;
074: }
075:
076: public void setErrorEnabled(boolean errorEnabled) {
077: this .errorEnabled = errorEnabled;
078: }
079:
080: public boolean isFatalEnabled() {
081: return fatalEnabled;
082: }
083:
084: public void setFatalEnabled(boolean fatalEnabled) {
085: this .fatalEnabled = fatalEnabled;
086: }
087:
088: private void logMessage(String level, Object s, Throwable throwable) {
089: printStream.print(level + ": " + s);
090: if (throwable != null) {
091: throwable.printStackTrace(System.out);
092: } else {
093: printStream.println();
094: }
095: }
096:
097: public void trace(Object o) {
098: if (traceEnabled) {
099: logMessage(TRACE, o, null);
100: }
101: }
102:
103: public void trace(Object o, Throwable throwable) {
104: if (traceEnabled) {
105: logMessage(TRACE, o, throwable);
106: }
107: }
108:
109: public void debug(Object s, Throwable throwable) {
110: if (debugEnabled) {
111: logMessage(DEBUG, s, throwable);
112: }
113: }
114:
115: public void debug(Object s) {
116: if (debugEnabled) {
117: logMessage(DEBUG, s, null);
118: }
119: }
120:
121: public void info(Object s, Throwable throwable) {
122: if (infoEnabled) {
123: logMessage(INFO, s, throwable);
124: }
125: }
126:
127: public void info(Object s) {
128: if (infoEnabled) {
129: logMessage(INFO, s, null);
130: }
131: }
132:
133: public void warn(Object s, Throwable throwable) {
134: logMessage(WARN, s, throwable);
135: }
136:
137: public void warn(Object s) {
138: logMessage(WARN, s, null);
139: }
140:
141: public void error(Object s, Throwable throwable) {
142: logMessage(ERROR, s, throwable);
143: }
144:
145: public void error(Object s) {
146: logMessage(ERROR, s, null);
147: }
148:
149: public void fatal(Object s, Throwable throwable) {
150: logMessage(FATAL, s, null);
151: }
152:
153: public void fatal(Object s) {
154: logMessage(ERROR, s, null);
155: }
156: }
|