001: package org.apache.velocity.runtime.log;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: /**
023: * Convenient wrapper for LogChute functions. This implements
024: * the RuntimeLogger methods (and then some). It is hoped that
025: * use of this will fully replace use of the RuntimeLogger.
026: *
027: * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
028: * @version $Id: Log.java 469919 2006-11-01 14:35:46Z henning $
029: */
030: public class Log {
031:
032: private LogChute chute;
033:
034: /**
035: * Creates a new Log that wraps a HoldingLogChute.
036: */
037: public Log() {
038: setLogChute(new HoldingLogChute());
039: }
040:
041: /**
042: * Creates a new Log that wraps the specified LogChute.
043: * @param chute
044: */
045: public Log(final LogChute chute) {
046: setLogChute(chute);
047: }
048:
049: /**
050: * Updates the LogChute wrapped by this Log instance.
051: * @param chute The new value for the log chute.
052: */
053: protected void setLogChute(final LogChute chute) {
054: if (chute == null) {
055: throw new NullPointerException(
056: "The LogChute cannot be set to null!");
057: }
058: this .chute = chute;
059: }
060:
061: /**
062: * Returns the LogChute wrapped by this Log instance.
063: * @return The LogChute wrapped by this Log instance.
064: */
065: protected LogChute getLogChute() {
066: return this .chute;
067: }
068:
069: protected void log(int level, Object message) {
070: getLogChute().log(level, String.valueOf(message));
071: }
072:
073: protected void log(int level, Object message, Throwable t) {
074: getLogChute().log(level, String.valueOf(message), t);
075: }
076:
077: /**
078: * Returns true if trace level messages will be printed by the LogChute.
079: * @return If trace level messages will be printed by the LogChute.
080: */
081: public boolean isTraceEnabled() {
082: return getLogChute().isLevelEnabled(LogChute.TRACE_ID);
083: }
084:
085: /**
086: * Log a trace message.
087: * @param message
088: */
089: public void trace(Object message) {
090: log(LogChute.TRACE_ID, message);
091: }
092:
093: /**
094: * Log a trace message and accompanying Throwable.
095: * @param message
096: * @param t
097: */
098: public void trace(Object message, Throwable t) {
099: log(LogChute.TRACE_ID, message, t);
100: }
101:
102: /**
103: * Returns true if debug level messages will be printed by the LogChute.
104: * @return True if debug level messages will be printed by the LogChute.
105: */
106: public boolean isDebugEnabled() {
107: return getLogChute().isLevelEnabled(LogChute.DEBUG_ID);
108: }
109:
110: /**
111: * Log a debug message.
112: * @param message
113: */
114: public void debug(Object message) {
115: log(LogChute.DEBUG_ID, message);
116: }
117:
118: /**
119: * Log a debug message and accompanying Throwable.
120: * @param message
121: * @param t
122: */
123: public void debug(Object message, Throwable t) {
124: log(LogChute.DEBUG_ID, message, t);
125: }
126:
127: /**
128: * Returns true if info level messages will be printed by the LogChute.
129: * @return True if info level messages will be printed by the LogChute.
130: */
131: public boolean isInfoEnabled() {
132: return getLogChute().isLevelEnabled(LogChute.INFO_ID);
133: }
134:
135: /**
136: * Log an info message.
137: * @param message
138: */
139: public void info(Object message) {
140: log(LogChute.INFO_ID, message);
141: }
142:
143: /**
144: * Log an info message and accompanying Throwable.
145: * @param message
146: * @param t
147: */
148: public void info(Object message, Throwable t) {
149: log(LogChute.INFO_ID, message, t);
150: }
151:
152: /**
153: * Returns true if warn level messages will be printed by the LogChute.
154: * @return True if warn level messages will be printed by the LogChute.
155: */
156: public boolean isWarnEnabled() {
157: return getLogChute().isLevelEnabled(LogChute.WARN_ID);
158: }
159:
160: /**
161: * Log a warning message.
162: * @param message
163: */
164: public void warn(Object message) {
165: log(LogChute.WARN_ID, message);
166: }
167:
168: /**
169: * Log a warning message and accompanying Throwable.
170: * @param message
171: * @param t
172: */
173: public void warn(Object message, Throwable t) {
174: log(LogChute.WARN_ID, message, t);
175: }
176:
177: /**
178: * Returns true if error level messages will be printed by the LogChute.
179: * @return True if error level messages will be printed by the LogChute.
180: */
181: public boolean isErrorEnabled() {
182: return getLogChute().isLevelEnabled(LogChute.ERROR_ID);
183: }
184:
185: /**
186: * Log an error message.
187: * @param message
188: */
189: public void error(Object message) {
190: log(LogChute.ERROR_ID, message);
191: }
192:
193: /**
194: * Log an error message and accompanying Throwable.
195: * @param message
196: * @param t
197: */
198: public void error(Object message, Throwable t) {
199: log(LogChute.ERROR_ID, message, t);
200: }
201:
202: }
|