Solved

java log4j example not working

Posted on 2014-03-26
1
885 Views
Last Modified: 2014-04-24
Hi,

I am running below log4j example.

https://logging.apache.org/log4j/1.2/manual.html

My code looks as below

package test;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("This is the Test Servlet");

		Enumeration headerNames = request.getHeaderNames();
		while (headerNames.hasMoreElements()) {
			String headerName = (String) headerNames.nextElement();
			out.print("<br/>Header Name: <em>" + headerName);
			String headerValue = request.getHeader(headerName);
			out.print("</em>, Header Value: <em>" + headerValue);
			out.println("</em>");
		}
	}

}

Open in new window

and other class is

 package com.foo;
 import org.apache.log4j.Logger;

 public class Bar {
   static Logger logger = Logger.getLogger(Bar.class);

   public void doIt() {
     logger.debug("Did it again!");
   }
 }

Open in new window


I am getting lot of compilation errors as i am not able to get references to
import org.apache.log4j.Logger;
and
 import org.apache.log4j.Logger;
 import org.apache.log4j.BasicConfigurator;

what are jars i need to include to fix these errors.

I am basically using eclipse and created one Dynamic WEb Project(TestLog) and then added above two classes to that project.

I am not sure what all jars i need to add and how to configure them in the eclipse to take effect into the TestLog project. Are there are any better links with more clear detailed description with screenshot on the set up and execution, output.


please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39957836
On the page that you linked to above, there is a menu on the left hand side which has a "Download" link on it. Follow that and then you can download the log4j library, which will ultimately give you a log4j-xxxxx.jar (the xxxx's are the version number) which you can include in the build path of your project.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now