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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • 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 log4j.property file in which I have ConsoleAppender & RollingFileAppender.The ConsoleAppender is printing the logs on Tomcate console but the log file is empty. log4.properties 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.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# ***** stdout uses PatternLayout.
log4j.appender.stdout.layout=org.apache.log4j.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.
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=E:\workspace\vcc\WEB-INF\example.log
# ***** Max file size is set to 100KB
log4j.appender.R.MaxFileSize=100KB
# ***** Keep one backup file
log4j.appender.R.MaxBackupIndex=1
# ***** R uses PatternLayout.
log4j.appender.R.layout=org.apache.log4j.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.
package com.abc.xyz;

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);
System.out.println("propfile:"+propfile);
//DOMConfigurator.configure(propfile);
PropertyConfigurator.configure(propfile);
}
}
}

please suggest me what is the problem?

thanks
 
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)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!