Solved

Log4j

Posted on 2007-03-20
2
3,005 Views
Last Modified: 2013-11-23
I have written a simple Java class and inlcuded log4j.jar in the classpath.

In log4j.properties I have written
log4j.rootCategory=DEBUG, C:\\logger.txt
log4j.appender.dest1=org.apache.log4j.ConsoleAppender
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

and in my class I have written

import org.apache.log4j.*;

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

public static void main(String[] args) {
logger.debug("111111111111111111111111111");
}

But I am getting the following error

log4j:ERROR Could not find value for key log4j.appender.C:\logger.txt
log4j:ERROR Could not instantiate appender named "C:\logger.txt".
log4j:WARN No appenders could be found for logger (com.myclass).
log4j:WARN Please initialize the log4j system properly.

Also nothing gets written to logger.txt
How can I fix this.
0
Comment
Question by:odumbe
2 Comments
 

Author Comment

by:odumbe
ID: 18755620
Also tried chaging
static Logger logger = Logger.getLogger(myclass .class);

to
static Logger logger = Logger.getLogger(com.myclass .class);

where com is the package name but still same problem.
0
 
LVL 11

Accepted Solution

by:
elfe69 earned 200 total points
ID: 18755666
Your log4j.properties could look like this to achieve what you want:

log4j.rootCategory=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.FileAppender
log4j.appender.dest1.File=C:/logger.txt
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

757 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

16 Experts available now in Live!

Get 1:1 Help Now