tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Chafee <a...@locus.apache.org>
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util ThreadPool.java
Date Thu, 06 Jul 2000 22:20:18 GMT
alex        00/07/06 15:20:18

  Modified:    src/etc  Tag: tomcat_32 server.xml
               src/share/org/apache/tomcat/logging Tag: tomcat_32
                        LogHelper.java Logger.java TomcatLogger.java
               src/share/org/apache/tomcat/util Tag: tomcat_32
                        ThreadPool.java
  Log:
  Integrate logging changes, including timestamps, into 3.2 beta
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.29.2.1  +53 -10    jakarta-tomcat/src/etc/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/etc/server.xml,v
  retrieving revision 1.29
  retrieving revision 1.29.2.1
  diff -u -r1.29 -r1.29.2.1
  --- server.xml	2000/06/29 20:46:44	1.29
  +++ server.xml	2000/07/06 22:20:16	1.29.2.1
  @@ -4,31 +4,74 @@
       <!-- Debug low-level events in XmlMapper startup -->
       <xmlmapper:debug level="0" />
   
  -    <!-- This is quite flexible; we can either have a log file per
  -         module in Tomcat (example: ContextManager) or we can have
  -         one for Servlets and one for Jasper, or we can just have
  -	 one tomcat.log for both Servlet and Jasper.
  +    <!-- 
   
  -	 If you omit "path" there, then stderr should be used.
  +    Logging:
   
  +         Logging in Tomcat is quite flexible; we can either have a log
  +         file per module (example: ContextManager) or we can have one
  +         for Servlets and one for Jasper, or we can just have one
  +         tomcat.log for both Servlet and Jasper.  Right now there are
  +         three standard log streams, "tc_log", "servlet_log", and
  +         "JASPER_LOG".  
  +
  +	 Path: 
  +
  +	 The file to which to output this log, relative to
  +	 TOMCAT_HOME.  If you omit a "path" value, then stderr or
  +	 stdout will be used.
  +
  +	 Verbosity: 
  +
  +	 Threshold for which types of messages are displayed in the
  +	 log.  Levels are inclusive; that is, "WARNING" level displays
  +	 any log message marked as warning, error, or fatal.  Default
  +	 level is WARNING.
  +
   	 verbosityLevel values can be: 
   	    FATAL
   	    ERROR
   	    WARNING 
               INFORMATION
               DEBUG
  +
  +	 Timestamps:
  +
  +	 By default, logs print a timestamp in the form "yyyy-MM-dd
  +	 hh:mm:ss" in front of each message.  To disable timestamps
  +	 completely, set 'timestamp="no"'. To use the raw
  +	 msec-since-epoch, which is more efficient, set
  +	 'timestampFormat="msec"'.  If you want a custom format, you
  +	 can use 'timestampFormat="hh:mm:ss"' following the syntax of
  +	 java.text.SimpleDateFormat (see Javadoc API).  For a
  +	 production environment, we recommend turning timestamps off,
  +	 or setting the format to "msec".
  +
  +	 Custom Output:
  +
  +	 "Custom" means "normal looking".  "Non-custom" means
  +	 "surrounded with funny xml tags".  In preparation for
  +	 possibly disposing of "custom" altogether, now the default is
  +	 'custom="yes"' (i.e. no tags)
  +
  +	 Per-component Debugging:
  +
  +	 Some components accept a "debug" attribute.  This further
  +	 enhances log output.  If you set the "debug" level for a
  +	 component, it may output extra debugging information.
       -->
   
  -    <!-- if you don't want messages on screen, add
  -         path="logs/tomcat.log" -->
  +    <!-- if you don't want messages on screen, add the attribute
  +            path="logs/tomcat.log" 
  +	 to the Logger element below
  +    -->
       <Logger name="tc_log" 
  -            customOutput="yes" 
               verbosityLevel = "INFORMATION" 
  -            timestamp="no" />
  +    />
   
       <Logger name="servlet_log" 
               path="logs/servlet.log"
  -            customOutput="yes" />
  +    />
   
       <Logger name="JASPER_LOG" 
   	    path="logs/jasper.log"
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +0 -1      jakarta-tomcat/src/share/org/apache/tomcat/logging/LogHelper.java
  
  Index: LogHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/logging/LogHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- LogHelper.java	2000/06/22 23:02:53	1.1
  +++ LogHelper.java	2000/07/06 22:20:17	1.1.2.1
  @@ -146,7 +146,6 @@
   		out.print(TomcatLogger.throwableToString(t));
   	}
   	else {
  -	    msg += "\n";
   	    logger.log(msg, t, level);
   	}
       }
  
  
  
  1.7.4.1   +75 -5     jakarta-tomcat/src/share/org/apache/tomcat/logging/Logger.java
  
  Index: Logger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/logging/Logger.java,v
  retrieving revision 1.7
  retrieving revision 1.7.4.1
  diff -u -r1.7 -r1.7.4.1
  --- Logger.java	2000/03/28 19:16:12	1.7
  +++ Logger.java	2000/07/06 22:20:17	1.7.4.1
  @@ -63,6 +63,8 @@
   import java.io.IOException;
   
   import java.util.*;
  +import java.text.DateFormat;
  +import java.text.SimpleDateFormat;
   
   /**
    * Interface for a logging object. A logging object provides mechanism
  @@ -295,15 +297,42 @@
        */
       public void setTimestamp(String value) {
   	if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value))
  -	    timeStamp = true;
  +	    timestamp = true;
   	else if ("false".equalsIgnoreCase(value) || "no".equalsIgnoreCase(value))
  -	    timeStamp = false;
  +	    timestamp = false;
       }
   
       public  boolean isTimestamp() {
  -	return timeStamp;
  +	return timestamp;
       }
  +
  +    /**
  +     * If we are timestamping at all, what format do we use to print
  +     * the timestamp? See java.text.SimpleDateFormat.
  +     *
  +     * Default = "yyyy-MM-dd hh:mm:ss". Special case: "msec" => raw
  +     * number of msec since epoch, very efficient but not
  +     * user-friendly
  +     **/
  +    public void setTimestampFormat(String value)
  +    {
  +	if (value.equalsIgnoreCase("msec"))
  +	    timestampRaw = true;
  +	else {
  +	    timestampRaw = false;
  +	    timestampFormat = value;
  +	    timestampFormatter = new SimpleDateFormat(timestampFormat);
  +	}
  +    }
       
  +    public String getTimestampFormat()
  +    {
  +	if (timestampRaw)
  +	    return "msec";
  +	else
  +	    return timestampFormat;
  +    }
  +    
       /**
        * Set the default output stream that is used by all logging
        * channels. 
  @@ -337,7 +366,30 @@
   	    custom = false;
       }
   
  -    protected boolean custom;
  +    protected String formatTimestamp(long msec) {
  +	StringBuffer buf = new StringBuffer();
  +	formatTimestamp(msec, buf);
  +	return buf.toString();
  +    }
  +
  +    // dummy variable to make SimpleDateFormat work right
  +    static java.text.FieldPosition position = new java.text.FieldPosition(DateFormat.YEAR_FIELD);
  +    
  +    protected void formatTimestamp(long msec, StringBuffer buf) {
  +	if (timestamp == false)
  +	    return;
  +	else if (timestampRaw) {
  +	    buf.append(Long.toString(msec));
  +	    return;
  +	}
  +	else {
  +	    Date d = new Date(msec);
  +	    timestampFormatter.format(d, buf, position);
  +	    return;
  +	}
  +    }
  +    
  +    protected boolean custom = true;
       protected Writer sink = defaultSink;
       String path;
       protected String name;
  @@ -346,5 +398,23 @@
       protected static Hashtable loggers = new Hashtable(5);
   
       private int level = WARNING;
  -    protected boolean timeStamp = true;
  +
  +    /**
  +     * Should we timestamp this log at all?
  +     **/
  +    protected boolean timestamp = true;
  +
  +    /**
  +     * true = The timestamp format is raw msec-since-epoch <br>
  +     * false = The timestamp format is a custom string to pass to SimpleDateFormat
  +     **/
  +    protected boolean timestampRaw = false;
  +
  +    /**
  +     * The timestamp format string, default is "yyyy-MM-dd hh:mm:ss"
  +     **/
  +    protected String timestampFormat = "yyyy-MM-dd hh:mm:ss";
  +
  +    protected SimpleDateFormat timestampFormatter
  +	= new SimpleDateFormat(timestampFormat);
   }
  
  
  
  1.7.2.1   +15 -7     jakarta-tomcat/src/share/org/apache/tomcat/logging/TomcatLogger.java
  
  Index: TomcatLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/logging/TomcatLogger.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- TomcatLogger.java	2000/06/22 23:10:25	1.7
  +++ TomcatLogger.java	2000/07/06 22:20:17	1.7.2.1
  @@ -115,7 +115,7 @@
   	
   	LogEntry(String message, Throwable t) {
   	    // avoid expensive system call
  -	    if (TomcatLogger.this.timeStamp)
  +	    if (TomcatLogger.this.timestamp)
   		this.date = System.currentTimeMillis();
   	    this.message = message;
   	    this.t = t;
  @@ -145,16 +145,17 @@
   		val.append("> ");
   	    }
   
  -	    if (TomcatLogger.this.timeStamp) {
  -		val.append(new Date(date).toString());
  -		val.append(" ");
  +	    if (TomcatLogger.this.timestamp) {
  +		formatTimestamp( date, val );
  +		val.append(" - ");
   	    }
   
  -	    if (message != null)
  +	    if (message != null) {
   		val.append(message);
  -
  +	    }
  +	    
   	    if (t != null) {
  -		val.append(" ");
  +		val.append(" - ");
   		val.append(throwableToString( t ));
   	    }
   
  @@ -224,6 +225,12 @@
   	setDaemon(true);
       }
   
  +    static char[] newline;
  +    static {
  +	String separator = System.getProperty("line.separator", "\n");
  +	newline = separator.toCharArray();
  +    }
  +    
       Runnable flusher = new Runnable() {
   	    public void run() {
   		do {
  @@ -233,6 +240,7 @@
   		    if (writer != null)
   			try {
   			    writer.write(logEntry.toString());
  +			    writer.write(newline);
   			    writer.flush();
   			} catch (Exception ex) { // IOException
   			    ex.printStackTrace();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.1   +25 -10    jakarta-tomcat/src/share/org/apache/tomcat/util/ThreadPool.java
  
  Index: ThreadPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/ThreadPool.java,v
  retrieving revision 1.9
  retrieving revision 1.9.2.1
  diff -u -r1.9 -r1.9.2.1
  --- ThreadPool.java	2000/06/07 12:11:05	1.9
  +++ ThreadPool.java	2000/07/06 22:20:17	1.9.2.1
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/ThreadPool.java,v
1.9 2000/06/07 12:11:05 shachor Exp $
  - * $Revision: 1.9 $
  - * $Date: 2000/06/07 12:11:05 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/ThreadPool.java,v
1.9.2.1 2000/07/06 22:20:17 alex Exp $
  + * $Revision: 1.9.2.1 $
  + * $Date: 2000/07/06 22:20:17 $
    *
    * ====================================================================
    *
  @@ -68,6 +68,8 @@
   import java.util.*;
   import java.io.*;
   
  +import org.apache.tomcat.logging.*; 
  +
   /**
    * A thread pool that is trying to copy the apache process management.
    *
  @@ -125,6 +127,11 @@
       protected boolean stopThePool;
   
       static int debug=0;
  +
  +    /**
  +     * Helper object for logging
  +     **/
  +    LogHelper loghelper = new LogHelper("tc_log", "ThreadPool");
       
       public ThreadPool() {
           maxThreads      = MAX_THREADS;
  @@ -202,8 +209,14 @@
                       while(currentThreadsBusy == currentThreadCount) {
                           try {
                               this.wait();
  -                        } catch(Throwable t) {
  -                            t.printStackTrace();
  +                        }
  +			// was just catch Throwable -- but no other
  +			// exceptions can be thrown by wait, right?
  +			// So we catch and ignore this one, since
  +			// it'll never actually happen, since nowhere
  +			// do we say pool.interrupt().
  +			catch(InterruptedException e) {
  +			    loghelper.log("Unexpected exception", e);
                           }
   
                           // Pool was stopped. Get away of the pool.
  @@ -238,6 +251,7 @@
   					 * Do nothing... The show must go on, we are shutting 
   					 * down the pool and nothing should stop that.
   					 */
  +		    loghelper.log("Ignored exception while shutting down thread pool", t, Logger.ERROR);
                   }
               }
               currentThreadsBusy = currentThreadCount = 0;
  @@ -350,7 +364,7 @@
       }
   
       void log( String s ) {
  -	System.out.println("ThreadPool: " + s );
  +	loghelper.log(s);
       }
       
       /** 
  @@ -382,11 +396,11 @@
                           break;
                       }
   
  -                    // Harvest idel threads.
  +                    // Harvest idle threads.
                       p.checkSpareControllers();
   
                   } catch(Throwable t) {
  -                    t.printStackTrace();
  +		    loghelper.log("Unexpected exception", t, Logger.ERROR);
                   }
               }
           }
  @@ -484,7 +498,7 @@
                               toRun.runIt(thData);
                           }
                       } catch(Throwable t) {
  -                        t.printStackTrace();
  +			loghelper.log("Caught exception executing " + toRun.toString() + ", terminating thread",
t);
                           /*
                           * The runnable throw an exception (can be even a ThreadDeath),
                           * signalling that the thread die.
  @@ -513,7 +527,8 @@
                           break;
                       }
                   } catch(InterruptedException ie) { /* for the wait operation */
  -                    ie.printStackTrace();
  +		    // can never happen, since we don't call interrupt
  +		    loghelper.log("Unexpected exception", ie);
                   }
               }
           }
  
  
  

Mime
View raw message