You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by al...@locus.apache.org on 2000/07/11 05:26:20 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/startup Tomcat.java
alex 00/07/10 20:26:20
Modified: src/share/org/apache/tomcat/startup Tomcat.java
Log:
Clean up logging
extends Logger.Helper (to get log() methods for free)
Don't System.exit(1) inside non-main methods
Print clearer startup messages to console and log:
- loading <config file path> to console
- loaded <config file path> to log
- Tomcat product name and version number
- *actual* location of the log file (not hardcoded "logs/tomcat.log")
- above says "console" if necessary :-)
- explanatory message if BindException: "Another service is using the
requested port (possibly another instance of Tomcat). Please stop the
other service and try again."
- use throwableToString in case it was a nested exception
Revision Changes Path
1.32 +28 -13 jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java
Index: Tomcat.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Tomcat.java 2000/06/23 01:21:57 1.31
+++ Tomcat.java 2000/07/11 03:26:19 1.32
@@ -10,7 +10,9 @@
import org.apache.tomcat.util.*;
import org.apache.tomcat.util.xml.*;
import org.apache.tomcat.core.*;
+import org.apache.tomcat.logging.*;
import org.xml.sax.*;
+import org.apache.tomcat.core.Constants;
/**
* Starter for Tomcat using XML.
@@ -18,12 +20,13 @@
*
* @author costin@dnt.ro
*/
-public class Tomcat {
+public class Tomcat extends Logger.Helper {
private static StringManager sm =
StringManager.getManager("org.apache.tomcat.resources");
Tomcat() {
+ super("tc_log");
}
// Set the mappings
@@ -125,6 +128,7 @@
/** Setup loggers when reading the configuration file - this will be
* called only when starting tomcat as deamon, all other modes will
* output to stderr
+ * *** [I don't think that's true any more -Alex]
*/
void setLogHelper( XmlMapper xh ) {
xh.addRule("Server/Logger",
@@ -166,7 +170,7 @@
public void execute(String args[] ) throws Exception {
if( ! processArgs( args ) ) {
- System.out.println(sm.getString("tomcat.wrongargs"));
+ // System.out.println(sm.getString("tomcat.wrongargs"));
printUsage();
return;
}
@@ -185,23 +189,35 @@
setLogHelper( xh );
File f = getConfigFile(cm);
+ log(sm.getString("tomcat.loading") + " " + f);
try {
xh.readXml(f,cm);
} catch( Exception ex ) {
- System.out.println(sm.getString("tomcat.fatalconfigerror") );
- ex.printStackTrace();
- System.exit(1);
+ log( sm.getString("tomcat.fatalconfigerror"), ex );
+ throw ex;
}
+ log(sm.getString("tomcat.loaded") + " " + f);
- System.out.println(sm.getString("tomcat.start"));
+ // by now, we should know where the log file is
+ String path = cm.getLogger().getPath();
+ if (path == null)
+ path = "console";
+ System.out.println(sm.getString("tomcat.start", new Object[] { path }));
+
cm.init(); // set up contexts
+ log(Constants.TOMCAT_NAME + " " + Constants.TOMCAT_VERSION);
// XXX Make this optional, and make sure it doesn't require
// a full start. It is called after init to make sure
// auto-configured contexts are initialized.
generateServerConfig( cm );
-
- cm.start(); // start serving
+ try {
+ cm.start(); // start serving
+ }
+ catch (java.net.BindException be) {
+ log("Starting Tomcat: " + be.getMessage(), Logger.ERROR);
+ System.out.println(sm.getString("tomcat.start.bindexception"));
+ }
}
/** This method will generate Server config files that
@@ -236,8 +252,9 @@
Tomcat tomcat=new Tomcat();
tomcat.execute( args );
} catch(Exception ex ) {
- System.out.println(sm.getString("tomcat.fatal") + ex );
- ex.printStackTrace();
+ System.out.println(sm.getString("tomcat.fatal"));
+ System.err.println(Logger.throwableToString(ex));
+ System.exit(1);
}
}
@@ -259,9 +276,7 @@
try {
xh.readXml(f,cm);
} catch( Exception ex ) {
- System.out.println(sm.getString("tomcat.fatalconfigerror") );
- ex.printStackTrace();
- System.exit(1);
+ throw new TomcatException("Fatal exception reading " + f, ex);
}
org.apache.tomcat.task.StopTomcat stopTc=