Thanks a lot Schultz,
my log4j logging works now, it prints the logs to stdout_20080523.log....
Actually, I followed the instruction on log4j docs..
I created initialization servlet, Log4jInit.class, that initializes log4j
and loaded on startup...
This initialization class looks like this:
public class Log4jInit extends HttpServlet {
public
void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
// if the log4j-init-file is not set, then no point in trying
if(file != null) {
PropertyConfigurator.configure(prefix+file);
}
}
public
void doGet(HttpServletRequest req, HttpServletResponse res) {
}
}
and adding this entry to web.xml file:
<servlet>
<servlet-name>log4j-init</servlet-name>
<servlet-class>com.foo.Log4jInit</servlet-class>
<init-param>
<param-name>log4j-init-file</param-name>
<param-value>WEB-INF/classes/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
In the class above, the static method configure(java.util.Properties
properties) of PropertyConfigurator class is called to initialize log4j
while you suggest to instantiate this object..
Well, another question I'd like to ask:
What is the difference between configuring log4j by calling this static
method (configure(java.util.Properties properties)) as written above and
instantiating PropertyConfigurator class and call its doConfigure() method
??
Christopher Schultz-2 wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Nashrul,
>
> nashrul wrote:
> | Hi all, I'm a beginner to web application [and log4j isn't working for
> me].
>
> [snip]
>
> | I also created log4j.properties file in <web-app>/WEB-INF/classes
> directory.
> | It contains the following [configuration]:
> |
> | log4j.logger.solmit=ALL, A
> | log4j.logger.org.apache=OFF, A
> |
> | log4j.appender.A=org.apache.log4j.ConsoleAppender
> | log4j.appender.A.layout=org.apache.log4j.PatternLayout
> | log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
> |
> |
> | I packaged this application into WebTest.war.
> | When I dropped this package into my Tomcat (Tomcat 5.5), and tried to
> access
> | web app using this url :http://localhost:8080/WebTest/start-web-test
> | I got error messages on my stderr_20080522 log:
> |
> | log4j:WARN No appenders could be found for logger
> | (org.apache.catalina.startup.Embedded).
> | log4j:WARN Please initialize the log4j system properly.
>
> This means that log4j was asked to log a message before the logging
> system was initialized. IIRC, log4j is supposed to automatically
> configure itself on first-use by looking for log4j.properties in the
> classpath, but that does not appear to be happening, here.
>
> I recall having the same problem on several of our projects, and we
> simply added this to our initialization listener:
>
> ~ new org.apache.log4j.PropertyConfigurator();
>
> This forces log4j to initialize itself using a properties file, and it
> will search the classpath for it -- so placing your log4j.properties
> file in WEB-INF/classes is appropriate.
>
> | Oh, I've also dropped log4j-1.2.13.jar and commons-logging-1.0.4.jar on
> | Tomcat/common/lib
>
> Do not do that. Remove those files from common/lib and anywhere else you
> tried putting them. Just use WEB-INF/lib in your own application for
> log4j.jar and commons-logging (if you actually need commons-logging).
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkg1dj8ACgkQ9CaO5/Lv0PDbqgCgouMNS+GuLE/a2qsP/u5/sCV8
> 494AnRMbIfdxLyY8MZoQz8p3r2Yufy7u
> =kSFm
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: [email protected]
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/Error-using-log4j-in-Tomcat-5.5-tp17400689p17420689.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To start a new topic, e-mail: [email protected]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]