Solved

Log4j

Posted on 2007-03-20
2
3,007 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
looking for unix program to search some keywords in side EAR WAR and JAR files 10 80
Checkbox and ListView in Android Layout 4 56
mockito example issue 8 62
diffSum example 4 21
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

919 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

18 Experts available now in Live!

Get 1:1 Help Now