You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/07/07 23:49:45 UTC
cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger LoggerBase.java
craigmcc 00/07/07 14:49:45
Modified: proposals/catalina/src/share/org/apache/tomcat Logger.java
proposals/catalina/src/share/org/apache/tomcat/logger
LoggerBase.java
Log:
Add support for filtered log output (based on verbosity level) similar
to the existing Tomcat logger, in addition to the existing log() calls
that are unconditional.
Revision Changes Path
1.3 +71 -10 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Logger.java
Index: Logger.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Logger.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Logger.java 2000/01/29 07:46:32 1.2
+++ Logger.java 2000/07/07 21:49:42 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Logger.java,v 1.2 2000/01/29 07:46:32 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/01/29 07:46:32 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Logger.java,v 1.3 2000/07/07 21:49:42 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/07/07 21:49:42 $
*
* ====================================================================
*
@@ -75,12 +75,31 @@
* to a Context, or higher level, Container.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2000/01/29 07:46:32 $
+ * @version $Revision: 1.3 $ $Date: 2000/07/07 21:49:42 $
*/
public interface Logger {
+ // ----------------------------------------------------- Manifest Constants
+
+
+ /**
+ * Verbosity level constants for log messages that may be filtered
+ * by the underlying logger.
+ */
+
+ public static final int FATAL = Integer.MIN_VALUE;
+
+ public static final int ERROR = 1;
+
+ public static final int WARNING = 2;
+
+ public static final int INFORMATION = 3;
+
+ public static final int DEBUG = 4;
+
+
// ------------------------------------------------------------- Properties
@@ -106,6 +125,22 @@
public String getInfo();
+ /**
+ * Return the verbosity level of this logger. Messages logged with a
+ * higher verbosity than this level will be silently ignored.
+ */
+ public int getVerbosity();
+
+
+ /**
+ * Set the verbosity level of this logger. Messages logged with a
+ * higher verbosity than this level will be silently ignored.
+ *
+ * @param verbosity The new verbosity level
+ */
+ public void setVerbosity(int verbosity);
+
+
// --------------------------------------------------------- Public Methods
@@ -120,12 +155,12 @@
/**
* Writes the specified message to a servlet log file, usually an event
* log. The name and type of the servlet log is specific to the
- * servlet container.
+ * servlet container. This message will be logged unconditionally.
*
- * @param msg A <code>String</code> specifying the message to be written
- * to the log file
+ * @param message A <code>String</code> specifying the message to be
+ * written to the log file
*/
- public void log(String msg);
+ public void log(String message);
/**
@@ -133,7 +168,8 @@
* The implementation of this method should call
* <code>log(msg, exception)</code> instead. This method is deprecated
* in the ServletContext interface, but not deprecated here to avoid
- * many useless compiler warnings.
+ * many useless compiler warnings. This message will be logged
+ * unconditionally.
*
* @param exception An <code>Exception</code> to be reported
* @param msg The associated message string
@@ -145,13 +181,38 @@
* Writes an explanatory message and a stack trace for a given
* <code>Throwable</code> exception to the servlet log file. The name
* and type of the servlet log file is specific to the servlet container,
- * usually an event log.
+ * usually an event log. This message will be logged unconditionally.
*
* @param message A <code>String</code> that describes the error or
* exception
* @param throwable The <code>Throwable</code> error or exception
*/
public void log(String message, Throwable throwable);
+
+
+ /**
+ * Writes the specified message to the servlet log file, usually an event
+ * log, if the logger is set to a verbosity level equal to or higher than
+ * the specified value for this message.
+ *
+ * @param message A <code>String</code> specifying the message to be
+ * written to the log file
+ * @param verbosity Verbosity level of this message
+ */
+ public void log(String message, int verbosity);
+
+
+ /**
+ * Writes the specified message and exception to the servlet log file,
+ * usually an event log, if the logger is set to a verbosity level equal
+ * to or higher than the specified value for this message.
+ *
+ * @param message A <code>String</code> that describes the error or
+ * exception
+ * @param throwable The <code>Throwable</code> error or exception
+ * @param verbosity Verbosity level of this message
+ */
+ public void log(String message, Throwable throwable, int verbosity);
/**
1.5 +97 -9 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/LoggerBase.java
Index: LoggerBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/LoggerBase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LoggerBase.java 2000/05/16 20:25:54 1.4
+++ LoggerBase.java 2000/07/07 21:49:44 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/LoggerBase.java,v 1.4 2000/05/16 20:25:54 craigmcc Exp $
- * $Revision: 1.4 $
- * $Date: 2000/05/16 20:25:54 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/LoggerBase.java,v 1.5 2000/07/07 21:49:44 craigmcc Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/07/07 21:49:44 $
*
* ====================================================================
*
@@ -80,7 +80,7 @@
* any property setting and lifecycle methods required for configuration.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.4 $ $Date: 2000/05/16 20:25:54 $
+ * @version $Revision: 1.5 $ $Date: 2000/07/07 21:49:44 $
*/
abstract class LoggerBase
@@ -109,6 +109,12 @@
protected PropertyChangeSupport support = new PropertyChangeSupport(this);
+ /**
+ * The verbosity level for above which log messages may be filtered.
+ */
+ protected int verbosity = ERROR;
+
+
// ------------------------------------------------------------- Properties
@@ -148,6 +154,52 @@
}
+ /**
+ * Return the verbosity level of this logger. Messages logged with a
+ * higher verbosity than this level will be silently ignored.
+ */
+ public int getVerbosity() {
+
+ return (this.verbosity);
+
+ }
+
+
+ /**
+ * Set the verbosity level of this logger. Messages logged with a
+ * higher verbosity than this level will be silently ignored.
+ *
+ * @param verbosity The new verbosity level
+ */
+ public void setVerbosity(int verbosity) {
+
+ this.verbosity = verbosity;
+
+ }
+
+
+ /**
+ * Set the verbosity level of this logger. Messages logged with a
+ * higher verbosity than this level will be silently ignored.
+ *
+ * @param verbosityLevel The new verbosity level, as a string
+ */
+ public void setVerbosityLevel(String verbosity) {
+
+ if ("FATAL".equalsIgnoreCase(verbosity))
+ this.verbosity = FATAL;
+ else if ("ERROR".equalsIgnoreCase(verbosity))
+ this.verbosity = ERROR;
+ else if ("WARNING".equalsIgnoreCase(verbosity))
+ this.verbosity = WARNING;
+ else if ("INFORMATION".equalsIgnoreCase(verbosity))
+ this.verbosity = INFORMATION;
+ else if ("DEBUG".equalsIgnoreCase(verbosity))
+ this.verbosity = DEBUG;
+
+ }
+
+
// --------------------------------------------------------- Public Methods
@@ -166,10 +218,10 @@
/**
* Writes the specified message to a servlet log file, usually an event
* log. The name and type of the servlet log is specific to the
- * servlet container.
+ * servlet container. This message will be logged unconditionally.
*
- * @param msg A <code>String</code> specifying the message to be written
- * to the log file
+ * @param message A <code>String</code> specifying the message to be
+ * written to the log file
*/
public abstract void log(String msg);
@@ -179,7 +231,8 @@
* The implementation of this method should call
* <code>log(msg, exception)</code> instead. This method is deprecated
* in the ServletContext interface, but not deprecated here to avoid
- * many useless compiler warnings.
+ * many useless compiler warnings. This message will be logged
+ * unconditionally.
*
* @param exception An <code>Exception</code> to be reported
* @param msg The associated message string
@@ -195,7 +248,7 @@
* Writes an explanatory message and a stack trace for a given
* <code>Throwable</code> exception to the servlet log file. The name
* and type of the servlet log file is specific to the servlet container,
- * usually an event log.
+ * usually an event log. This message will be logged unconditionally.
*
* @param msg A <code>String</code> that describes the error or
* exception
@@ -217,6 +270,41 @@
}
log(buf.toString());
+
+ }
+
+
+ /**
+ * Writes the specified message to the servlet log file, usually an event
+ * log, if the logger is set to a verbosity level equal to or higher than
+ * the specified value for this message.
+ *
+ * @param message A <code>String</code> specifying the message to be
+ * written to the log file
+ * @param verbosity Verbosity level of this message
+ */
+ public void log(String message, int verbosity) {
+
+ if (this.verbosity >= verbosity)
+ log(message);
+
+ }
+
+
+ /**
+ * Writes the specified message and exception to the servlet log file,
+ * usually an event log, if the logger is set to a verbosity level equal
+ * to or higher than the specified value for this message.
+ *
+ * @param message A <code>String</code> that describes the error or
+ * exception
+ * @param throwable The <code>Throwable</code> error or exception
+ * @param verbosity Verbosity level of this message
+ */
+ public void log(String message, Throwable throwable, int verbosity) {
+
+ if (this.verbosity >= verbosity)
+ log(message, throwable);
}