This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes not logging as coded Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "not logging as coded" Watch "not logging as coded" New topic

not logging as coded

Srinivasa Kadiyala
Ranch Hand

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

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

# 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
# Keep one backup file

#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() {

//"*********Invoked Logging*************");
String prefix = getServletContext().getRealPath("/");
String config = getInitParameter("log4j-init-file");
//"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>>>>>>>>>>>>>>>>>>

<<<<<<<<<<<<<<<<<<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
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Jun 10, 2004
Posts: 237
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

Joined: Jun 10, 2004
Posts: 237
Hi Carol

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

Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Perhaps a tomcat user can help out. If I were you I would modify the subject line to include log4j and tomcat.
It is sorta covered in the JavaRanch Style Guide.
subject: not logging as coded
It's not a secret anymore!