• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not logging as coded

 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 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.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said it isn't writing to the log file. Does that directory exist on the dev server? What IS it doing, logging to console or no logging at all?

Adding -Dlog4j.debug can be helpful if it is not logging at all. See log4j short manual for info on adding that to the tomcat options if needed.
 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The directory and file name exists on the dev server.

It is writtng. But writting to file localhost_log.txt

I see that this file name is mentioned in server.xml. Is it necessarry ? Can I delete that?

The line is hereunder for your review:

<Logger className="org.apache.catalina.logger.FileLogger" debug="0" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true" verbosity="1"/>


Thanks for the reply
 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carol

Can you look at my code and give me some clue?

Thanks
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps a tomcat user can help out. If I were you I would modify the subject line to include log4j and tomcat.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic