ceki 2004/03/27 09:31:56 Modified: examples/tiny-webapp/Hello build.xml examples/tiny-webapp/Hello/src/WEB-INF web.xml examples/tiny-webapp/Tata build.xml examples/tiny-webapp/Hello/src/java/wombat HelloServlet.java examples/tiny-webapp/Tata/src/java/wombat TataServlet.java examples/tiny-webapp/Tata/src/WEB-INF web.xml examples/tiny-webapp/Tata/src/resources log4j.xml Added: examples/tiny-webapp/Hello .cvsignore README.txt build.properties.sample examples/tiny-webapp/Tata build.properties.sample .cvsignore README.txt examples/tiny-webapp/Hello/src/java/wombat InitServlet.java examples/tiny-webapp/Tata/src/html index.html examples/tiny-webapp/Hello/src/html index.html examples/tiny-webapp INSTALL.txt Removed: examples/tiny-webapp/Hello/src/java/wombat Log4jInit.java examples/tiny-webapp/Tata/src/html hello.html examples/tiny-webapp/Hello/src/html hello.html examples/tiny-webapp/Tata/src/java/wombat Log4jInit.java Log:
Added documentation to the example web-apps Revision Changes Path 1.2 +10 -8 logging-log4j/examples/tiny-webapp/Hello/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/logging-log4j/examples/tiny-webapp/Hello/build.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- build.xml 27 Mar 2004 15:55:12 -0000 1.1 +++ build.xml 27 Mar 2004 17:31:56 -0000 1.2 @@ -4,21 +4,23 @@ <property environment="env"/> - <property name="tomcat.hom-" value="/home/ceki/ASF/jakarta-tomcat-4.1.30/"/> - <property name="tomcat.home" value="/home/ceki/ASF/jakarta-tomcat-5.0.19/"/> - + <!-- The build.properties file defines variables dependent of the host machine --> + <property file="build.properties"/> + <property name="src.dir" value="${basedir}/src/java/"/> <property name="javac.dest" value="${basedir}/classes"/> - + + <property name="webapp-name" value="hello"/> <path id="compile.classpath"> <pathelement location="${build.home}/classes"/> - <fileset dir="./lib" includes="*.jar"/> + <pathelement location="${log4j.jar}"/> + <pathelement location="${servlet.jar}"/> </path> <target name="clean" depends=""> <delete dir="${javac.dest}/" /> - <delete dir="./hello.war" /> + <delete dir="./${webapp-name}.war" /> </target> <target name="compile"> @@ -30,7 +32,7 @@ </target> <target name="war" depends="compile"> - <war warfile="hello.war" webxml="src/WEB-INF/web.xml"> + <war warfile="${webapp-name}.war" webxml="src/WEB-INF/web.xml"> <classes dir="classes"/> <zipfileset dir="src/resources" prefix="WEB-INF/classes"/> <zipfileset dir="src/html" prefix=""/> @@ -41,7 +43,7 @@ <!-- Uncompress war file --> <!-- ================================================================= --> <target name="deploy" depends="war"> - <unjar src="hello.war" dest="${tomcat.home}/webapps/hello"/> + <unjar src="${webapp-name}.war" dest="${target.webapp.dir}/${webapp-name}"/> </target> </project> 1.1 logging-log4j/examples/tiny-webapp/Hello/.cvsignore Index: .cvsignore =================================================================== build.properties 1.1 logging-log4j/examples/tiny-webapp/Hello/README.txt Index: README.txt =================================================================== The tiny web-applications Hello and Tata demonstrate how multiple web-apps can live in separate logging contexts. For installation instructions see the file INSTALL.txt in the parent directory. Note that you will need log4j-VERSION.jar to compile the web-applications but it should not be included in the web-application's jar file. 1.1 logging-log4j/examples/tiny-webapp/Hello/build.properties.sample Index: build.properties.sample =================================================================== # Sample build.properties file # The path to the web-server home webserver.home=/java/tomcat/ # The deployment target directory on the web server target.webapp.dir=${webserver.home}/webapps # We need servlet to compile the various servlets. servlet.jar=/java/servlet.jar # We need log4j-x.jar to run these examples log4j.jar=../../../log4j-1.3alpha.jar 1.2 +2 -2 logging-log4j/examples/tiny-webapp/Hello/src/WEB-INF/web.xml Index: web.xml =================================================================== RCS file: /home/cvs/logging-log4j/examples/tiny-webapp/Hello/src/WEB-INF/web.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- web.xml 27 Mar 2004 15:55:12 -0000 1.1 +++ web.xml 27 Mar 2004 17:31:56 -0000 1.2 @@ -3,8 +3,8 @@ <web-app> <servlet> - <servlet-name>log4j-init</servlet-name> - <servlet-class>wombat.Log4jInit</servlet-class> + <servlet-name>some-init-servlet</servlet-name> + <servlet-class>wombat.InitServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> 1.2 +11 -7 logging-log4j/examples/tiny-webapp/Tata/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/logging-log4j/examples/tiny-webapp/Tata/build.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- build.xml 27 Mar 2004 15:55:12 -0000 1.1 +++ build.xml 27 Mar 2004 17:31:56 -0000 1.2 @@ -1,22 +1,26 @@ <?xml version="1.0" encoding="UTF-8" ?> -<project name="Tata Webapp Build Script" default="compile" basedir="."> +<project name="Webapp Build Script" default="compile" basedir="."> <property environment="env"/> - <property name="tomcat.home" value="/home/ceki/ASF/jakarta-tomcat-4.1.30/"/> + <!-- The build.properties file defines variables dependent of the host machine --> + <property file="build.properties"/> + <property name="src.dir" value="${basedir}/src/java/"/> <property name="javac.dest" value="${basedir}/classes"/> - + + <property name="webapp-name" value="tata"/> <path id="compile.classpath"> <pathelement location="${build.home}/classes"/> - <fileset dir="./lib" includes="*.jar"/> + <pathelement location="${log4j.jar}"/> + <pathelement location="${servlet.jar}"/> </path> <target name="clean" depends=""> <delete dir="${javac.dest}/" /> - <delete dir="./tata.war" /> + <delete dir="./${webapp-name}.war" /> </target> <target name="compile"> @@ -28,7 +32,7 @@ </target> <target name="war" depends="compile"> - <war warfile="tata.war" webxml="src/WEB-INF/web.xml"> + <war warfile="${webapp-name}.war" webxml="src/WEB-INF/web.xml"> <classes dir="classes"/> <zipfileset dir="src/resources" prefix="WEB-INF/classes"/> <zipfileset dir="src/html" prefix=""/> @@ -39,7 +43,7 @@ <!-- Uncompress war file --> <!-- ================================================================= --> <target name="deploy" depends="war"> - <unjar src="tata.war" dest="${tomcat.home}/webapps/tata"/> + <unjar src="${webapp-name}.war" dest="${target.webapp.dir}/${webapp-name}"/> </target> </project> 1.1 logging-log4j/examples/tiny-webapp/Tata/build.properties.sample Index: build.properties.sample =================================================================== # Sample build.properties file # The path to the web-server home webserver.home=/java/tomcat/ # The deployment target directory on the web server target.webapp.dir=${webserver.home}/webapps # We need servlet to compile the various servlets. servlet.jar=/java/servlet.jar # We need log4j-x.jar to run these examples log4j.jar=../../../log4j-1.3alpha.jar 1.1 logging-log4j/examples/tiny-webapp/Tata/.cvsignore Index: .cvsignore =================================================================== build.properties tata.war 1.1 logging-log4j/examples/tiny-webapp/Tata/README.txt Index: README.txt =================================================================== The tiny web-applications Hello and Tata demonstrate how multiple web-apps can live in separate logging contexts. For installation instructions see the file INSTALL.txt in the parent directory. Note that you will need log4j-VERSION.jar to compile the web-applications but it should not be included in the web-application's jar file. 1.2 +3 -6 logging-log4j/examples/tiny-webapp/Hello/src/java/wombat/HelloServlet.java Index: HelloServlet.java =================================================================== RCS file: /home/cvs/logging-log4j/examples/tiny-webapp/Hello/src/java/wombat/HelloServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HelloServlet.java 27 Mar 2004 15:55:12 -0000 1.1 +++ HelloServlet.java 27 Mar 2004 17:31:56 -0000 1.2 @@ -23,13 +23,10 @@ response.setContentType("text/html"); PrintWriter out = response.getWriter(); - if(logger!=null) { - // if defined, use the logger as any other logger - logger.info("About to say hello to "+name); - } - + logger.info("About to say hello to "+name); + out.println("<HTML><BODY>"); - out.println("<H2> XHello " + name + ". How are you?</H2>"); + out.println("<H2> Hello there " + name + ". How are you today?</H2>"); out.println("</BODY></HTML>"); out.close(); } 1.1 logging-log4j/examples/tiny-webapp/Hello/src/java/wombat/InitServlet.java Index: InitServlet.java =================================================================== package wombat; import org.apache.log4j.*; import org.apache.log4j.spi.RootCategory; import javax.servlet.http.*; import javax.servlet.*; public class InitServlet extends HttpServlet { static Logger logger = Logger.getLogger(InitServlet.class); public void init() { logger.info("Logging initialized for Hello."); } public void doGet(HttpServletRequest req, HttpServletResponse res) { // nothing to do } } 1.1 logging-log4j/examples/tiny-webapp/Tata/src/html/index.html Index: index.html =================================================================== <HTML> <BODY> <FORM METHOD="POST" ACTION="/tata/TataServlet"> Enter your name: <INPUT TYPE="text" NAME="name" SIZE="10"> <INPUT TYPE="submit"> </FORM> </BODY> </HTML> 1.1 logging-log4j/examples/tiny-webapp/Hello/src/html/index.html Index: index.html =================================================================== <HTML> <BODY> <FORM METHOD="POST" ACTION="/hello/HelloServlet"> Your name: <INPUT TYPE="text" NAME="name" SIZE="10"> <INPUT TYPE="submit"> </FORM> </BODY> </HTML> 1.1 logging-log4j/examples/tiny-webapp/INSTALL.txt Index: INSTALL.txt =================================================================== The tiny web-applications Hello and Tata demonstrate how multiple web-apps can live in separate logging contexts. Here are the installation steps to run the examples. Steps performed on the Java Web Server (Servlet Container) ========================================================= - Place log4j-VERSION.jar, where VERSION is 1.3 or above, in your web server's (YES, server's) shared class loader directory. For example, for Tomcat versions 4 or 5, that would be common/lib/, for Resin version 2.1.x that would be the lib/ directory under the Resin installation folder. Other Servlet containers such as Jetty also have folders for shared jar files. - When launching your java web *server*, make sure to add the log4j.repositorySelectorClass system property on the java command line. For the JNDIContextSelector the exact system property to add is: -Dlog4j.repositorySelectorClass="JNDI" - You can now run the supplied web-applications hello.war and tata.war. Steps performed per web-application ================================== - In each web-application's web.ml file add a JNDI environment entry for the log4j logging context name. For the "Hello" web-application this takes the following form: <env-entry> <description>JNDI logging context for this app</description> <env-entry-name>log4j/context-name</env-entry-name> <env-entry-value>hello</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry> See also the file examples/tiny-webapp/Hello/src/WEB-INF/web.xml - Include a log4j.properties or log4j.xml configuration file in your web-application's WEB-INF/classes directory. This file will be automatically taken to configure the repository instance specific for your web-application. Note that you will need log4j-VERSION.jar to compile the web-applications but log4j-VERSION.jar file should not be included within the web-application's jar file. For more options see the javadoc for JNDIContextSelector. 1.2 +1 -1 logging-log4j/examples/tiny-webapp/Tata/src/java/wombat/TataServlet.java Index: TataServlet.java =================================================================== RCS file: /home/cvs/logging-log4j/examples/tiny-webapp/Tata/src/java/wombat/TataServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TataServlet.java 27 Mar 2004 15:55:12 -0000 1.1 +++ TataServlet.java 27 Mar 2004 17:31:56 -0000 1.2 @@ -26,7 +26,7 @@ logger.info("About to say Tata to "+name); out.println("<HTML><BODY>"); - out.println("<H2> Tata " + name + ". How are you?</H2>"); + out.println("<H2>Many tata's to you " + name + ". How are you today?</H2>"); out.println("</BODY></HTML>"); out.close(); } 1.2 +0 -6 logging-log4j/examples/tiny-webapp/Tata/src/WEB-INF/web.xml Index: web.xml =================================================================== RCS file: /home/cvs/logging-log4j/examples/tiny-webapp/Tata/src/WEB-INF/web.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- web.xml 27 Mar 2004 15:55:12 -0000 1.1 +++ web.xml 27 Mar 2004 17:31:56 -0000 1.2 @@ -3,12 +3,6 @@ <web-app> <servlet> - <servlet-name>log4j-init</servlet-name> - <servlet-class>wombat.Log4jInit</servlet-class> - <load-on-startup>1</load-on-startup> - </servlet> - - <servlet> <servlet-name>TataServlet</servlet-name> <servlet-class>wombat.TataServlet</servlet-class> </servlet> 1.2 +7 -7 logging-log4j/examples/tiny-webapp/Tata/src/resources/log4j.xml Index: log4j.xml =================================================================== RCS file: /home/cvs/logging-log4j/examples/tiny-webapp/Tata/src/resources/log4j.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- log4j.xml 27 Mar 2004 15:55:12 -0000 1.1 +++ log4j.xml 27 Mar 2004 17:31:56 -0000 1.2 @@ -4,17 +4,17 @@ <log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'> - <!-- Append log to the CONSOLE appender --> - <appender name="console" class="org.apache.log4j.ConsoleAppender"> + <appender name="ROLL" class="org.apache.log4j.FileAppender"> + <param name="File" value="/tata.log"/> + <param name="Append" value="false"/> <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="TATA %-5p [%t] %c - %m%n"/> - </layout> + <param name="ConversionPattern" value="TATA %r %-5p %c - %m%n"/> + </layout> </appender> + <root> <level value="debug"/> - <appender-ref ref="console"/> + <appender-ref ref="FILE" /> </root> - - </log4j:configuration> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]