Ah, sorry. I didn't look closely enough at your code. The first example on this page shows how to read a properties file using getResourceAsStream(). Use that to get the properties file for the Configurator.
http://nagoya.apache.org/wiki/apachewiki.cgi?Tomcat/Howto On Thu, 2004-10-28 at 20:25, Ben Souther wrote: > Try pulling out the: > PropertyConfigurator.configure("log4j.properties") > line. > > You shouldn't need it. > Just let log4j find it in your classes directory. > > > On Thu, 2004-10-28 at 20:14, Mufaddal Khumri wrote: > > I just did that. I have a WEB-INF/classes/log4j.properties file with > > the following: > > > > # initialise root logger with level DEBUG and call it A1 > > log4j.rootLogger=DEBUG, A1 > > # set the appender to be FileAppender > > log4j.appender.A1=org.apache.log4j.FileAppender > > # set set that layout to be SimpleLayout > > log4j.appender.A1.layout=org.apache.log4j.SimpleLayout > > > > I have this in the java code: > > Logger logger = Logger.getLogger(Helper.class); > > PropertyConfigurator.configure("log4j.properties"); > > > > I get the following exception: > > java.io.FileNotFoundException: log4j.properties (No such file or > > directory) > > at java.io.FileInputStream.open(Native Method) > > at java.io.FileInputStream.<init>(FileInputStream.java:106) > > at java.io.FileInputStream.<init>(FileInputStream.java:66) > > at > > org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.j > > ava:297) > > > > > > On Oct 28, 2004, at 4:56 PM, Ben Souther wrote: > > > > > Log4j looks on your class path for a properties file > > > "log4j.properties". If you put the file in WEB-INF/classes > > > it will find it. > > > > > > Here's a real simple example: > > > log4j.rootCategory=DEBUG, dest1 > > > log4j.appender.dest1=org.apache.log4j.RollingFileAppender > > > log4j.appender.dest1.file=/usr/local/tomcat/logs/myapp.log > > > log4j.appender.dest1.layout=org.apache.log4j.PatternLayout > > > log4j.appender.dest1.layout.ConversionPattern=%-5p: %m%n > > > > > > > > > > > > > > > > > > On Thu, 2004-10-28 at 19:08, Mufaddal Khumri wrote: > > >> Hi, > > >> > > >> Am new to log4j. Am using Tomcat 5 and my webapp-myNiceWebApp is in > > >> Tomcat/webapps/myNiceWebApp > > >> > > >> I have a class that I have the following code in: > > >> > > >> Logger logger = Logger.getLogger(Helper.class); > > >> SimpleLayout layout = new SimpleLayout(); > > >> > > >> FileAppender appender = null; > > >> try > > >> { > > >> appender = new FileAppender(layout,"output1.txt",false); > > >> } > > >> catch(Exception e) > > >> { > > >> e.printStackTrace(); > > >> } > > >> > > >> logger.addAppender(appender); > > >> logger.setLevel((Level)Level.DEBUG); > > >> > > >> logger.debug("some message"); > > >> > > >> Que 1. Where does the file output1.txt get created? > > >> Que 2. How does log4j know where to create it and can it be > > >> controlled? > > >> Que 3. I am going to use a configuration file either use the > > >> DOMConfigurator or PropertyConfigurator to load the log4j properties. > > >> Where do i place this file log4j configuration file? > > >> > > >> Thanks, > > >> > > >> > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > Mufaddal Khumri > > Software Developer > > Waves In Motion > > Phone: 602 956 7080 x 26 > > Email: [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
