File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Logging ..adivse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Logging ..adivse" Watch "Logging ..adivse" New topic
Author

Logging ..adivse

Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
I have my log4j.properties file as below:

<<<<<<<<<<<<<log4j.props file>>>>>>>>>>>>>>>>>>>>>>
log4j.rootLogger=info, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
#log4j.appender.stdout.layout.ConversionPattern=%d %-5p %c "%l" %x - %m%n
log4j.appender.stdout.layout.ConversionPattern=%d %-5p %c{2} %x - %m%n

# Set appender for log files
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=d:/tomcat-4/logs/myApp/myApp.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
#log4j.appender.R.layout.ConversionPattern=%d %-5p %c %l - %m%n
log4j.appender.R.layout.ConversionPattern=%d %-5p %c{2} - %m%n

<<<<<<<<<<<<<<<<<< ends here>>>>>>>>>>>>>>>>>>

<<<<<<<<<<<<<<<LogInit servlet>>>>>>>>>>>>>>>>>>>

public class LogInitServlet extends HttpServlet {

// private Logger log = Logger.getLogger(LogInitServlet.class);

public void init() {

// log.info("*********Invoked Logging*************");
String prefix = getServletContext().getRealPath("/");
String config = getInitParameter("log4j-init-file");
// log.info("Initializing Log4j from config file: " + prefix + config);

if (config != null) {
PropertyConfigurator.configure(prefix + config);
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response) {

//
}
}

<<<<<<<<<<<<< ends here>>>>>>>>>>>>>>>>>>>>>>>>>>>>


<<<<< added to web.xml>>>>>>>>>>>>>>>>>>
<servlet>
<servlet-name>Log4JInit</servlet-name>
<servlet-class>com.abc.myApp.logging.LogInitServlet</servlet-class>
<init-param>
<param-name>log4j-init-file</param-name>
<param-value>/WEB-INF/classes/resources/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


<<<<<<<<<<<<<<<<<<ends here>>>>>>>>>>>>>>>>>>>>>>>>

The directory and file name exists on the dev server.

The logging is working fine when I execute the code on Tomcat on my m/c. But when I push to dev server, it is not writting to myApp.log.

Appreciate help.


Srini
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logging ..adivse
 
Similar Threads
Help Please -log4j:WARN No appenders could be found for logger
log4j...
not logging as coded
log4j and Maven
log4j is printing only once at Start. unable to figure out the issue, please help