Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Logs are not printig

Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all I have one file in which I have ConsoleAppender & RollingFileAppender.The ConsoleAppender is printing the logs on Tomcate console but the log file is empty. is given below
# ***** Set root logger level to WARN and its two appenders to stdout and R.
log4j.rootLogger=ALL, stdout, R

# ***** stdout is set to be a ConsoleAppender.
# ***** stdout uses PatternLayout.
# ***** Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

# ***** R is set to be a RollingFileAppender.
# ***** Max file size is set to 100KB
# ***** Keep one backup file
# ***** R uses PatternLayout.
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

here I have created a example.log file at E:\workspace\vcc\WEB-INF\example.log

I have also created a Log4jServelt which will load the propertiy file in container during startup.

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
//import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

public class Log4JServlet extends HttpServlet {

public void init() throws ServletException{
String log4jfile = getInitParameter("log4j-file");
System.out.println("Log file name from Http Servlet:"+log4jfile);
if (log4jfile != null) {
String propfile = getServletContext().getRealPath(log4jfile);

please suggest me what is the problem?

Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!