001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Jul 19, 2005
014: * @author James Dixon
015: *
016: */
017:
018: package org.pentaho.ui.servlet;
019:
020: import javax.servlet.http.HttpServlet;
021: import javax.servlet.http.HttpServletRequest;
022:
023: import org.apache.commons.logging.Log;
024: import org.pentaho.core.session.IPentahoSession;
025: import org.pentaho.core.system.PentahoSystem;
026: import org.pentaho.core.util.UIUtil;
027: import org.pentaho.util.logging.ILogger;
028:
029: public abstract class ServletBase extends HttpServlet implements
030: ILogger {
031:
032: public static final boolean debug = PentahoSystem.debug;
033:
034: private int loggingLevel = ERROR;
035:
036: private String logId = ""; //$NON-NLS-1$
037:
038: protected IPentahoSession getPentahoSession(
039: HttpServletRequest request) {
040: return UIUtil.getPentahoSession(request);
041: }
042:
043: public abstract Log getLogger();
044:
045: public String getLogId() {
046: return logId;
047: }
048:
049: public void setLogId(String lId) {
050: logId = lId;
051: }
052:
053: /* ILogger Implementation */
054:
055: public String getObjectName() {
056: return this .getClass().getName();
057: }
058:
059: public int getLoggingLevel() {
060: return loggingLevel;
061: }
062:
063: public void setLoggingLevel(int logLevel) {
064: this .loggingLevel = logLevel;
065: }
066:
067: public void trace(String message) {
068: if (loggingLevel <= TRACE) {
069: getLogger().trace(getLogId() + message);
070: }
071: }
072:
073: public void debug(String message) {
074: if (loggingLevel <= DEBUG) {
075: getLogger().debug(getLogId() + message);
076: }
077: }
078:
079: public void info(String message) {
080: if (loggingLevel <= INFO) {
081: getLogger().info(getLogId() + message);
082: }
083: }
084:
085: public void warn(String message) {
086: if (loggingLevel <= WARN) {
087: getLogger().warn(getLogId() + message);
088: }
089: }
090:
091: public void error(String message) {
092: if (loggingLevel <= ERROR) {
093: getLogger().error(getLogId() + message);
094: }
095: }
096:
097: public void fatal(String message) {
098: if (loggingLevel <= FATAL) {
099: getLogger().fatal(getLogId() + message);
100: }
101: }
102:
103: public void trace(String message, Throwable error) {
104: if (loggingLevel <= TRACE) {
105: getLogger().trace(getLogId() + message, error);
106: }
107: }
108:
109: public void debug(String message, Throwable error) {
110: if (loggingLevel <= DEBUG) {
111: getLogger().debug(getLogId() + message, error);
112: }
113: }
114:
115: public void info(String message, Throwable error) {
116: if (loggingLevel <= INFO) {
117: getLogger().info(getLogId() + message, error);
118: }
119: }
120:
121: public void warn(String message, Throwable error) {
122: if (loggingLevel <= WARN) {
123: getLogger().warn(getLogId() + message, error);
124: }
125: }
126:
127: public void error(String message, Throwable error) {
128: if (loggingLevel <= ERROR) {
129: getLogger().error(getLogId() + message, error);
130: }
131: }
132:
133: public void fatal(String message, Throwable error) {
134: if (loggingLevel <= FATAL) {
135: getLogger().fatal(getLogId() + message, error);
136: }
137: }
138:
139: }
|