001: /*
002: * Copyright 2006 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.dev.shell.tomcat;
017:
018: import com.google.gwt.core.ext.TreeLogger;
019:
020: /**
021: * Maps Tomcat's commons logger onto the GWT shell's tree logger.
022: */
023: public class CommonsLoggerAdapter implements
024: org.apache.commons.logging.Log {
025:
026: private TreeLogger log;
027:
028: public CommonsLoggerAdapter(String name) {
029: // NOTE: this is ugly, but I don't know of any other way to get a
030: // non-static log to which we can delegate.
031: //
032: log = EmbeddedTomcatServer.sTomcat.getLogger();
033: }
034:
035: public void debug(Object message) {
036: doLog(TreeLogger.SPAM, message, null);
037: }
038:
039: public void debug(Object message, Throwable t) {
040: doLog(TreeLogger.SPAM, message, t);
041: }
042:
043: public void error(Object message) {
044: doLog(TreeLogger.WARN, message, null);
045: }
046:
047: public void error(Object message, Throwable t) {
048: doLog(TreeLogger.WARN, message, t);
049: }
050:
051: public void fatal(Object message) {
052: doLog(TreeLogger.WARN, message, null);
053: }
054:
055: public void fatal(Object message, Throwable t) {
056: doLog(TreeLogger.WARN, message, t);
057: }
058:
059: public void info(Object message) {
060: // Intentionally low-level to us.
061: doLog(TreeLogger.TRACE, message, null);
062: }
063:
064: public void info(Object message, Throwable t) {
065: // Intentionally low-level to us.
066: doLog(TreeLogger.TRACE, message, t);
067: }
068:
069: public boolean isDebugEnabled() {
070: return log.isLoggable(TreeLogger.SPAM);
071: }
072:
073: public boolean isErrorEnabled() {
074: return log.isLoggable(TreeLogger.WARN);
075: }
076:
077: public boolean isFatalEnabled() {
078: return log.isLoggable(TreeLogger.WARN);
079: }
080:
081: public boolean isInfoEnabled() {
082: // Intentionally low-level to us.
083: return log.isLoggable(TreeLogger.TRACE);
084: }
085:
086: public boolean isTraceEnabled() {
087: // Intentionally low-level to us.
088: return log.isLoggable(TreeLogger.SPAM);
089: }
090:
091: public boolean isWarnEnabled() {
092: return log.isLoggable(TreeLogger.WARN);
093: }
094:
095: public void trace(Object message) {
096: // Intentionally low-level to us.
097: doLog(TreeLogger.DEBUG, message, null);
098: }
099:
100: public void trace(Object message, Throwable t) {
101: // Intentionally low-level to us.
102: doLog(TreeLogger.DEBUG, message, t);
103: }
104:
105: public void warn(Object message) {
106: doLog(TreeLogger.WARN, message, null);
107: }
108:
109: public void warn(Object message, Throwable t) {
110: doLog(TreeLogger.WARN, message, t);
111: }
112:
113: private void doLog(TreeLogger.Type type, Object message, Throwable t) {
114: String msg = message.toString();
115: log.log(type, msg, t);
116: }
117: }
|