Solved

Log4j

Posted on 2007-03-20
2
3,022 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 53
Crystal Reports Licensing Questions 4 62
Tagging and Merging on Branch 1 42
wild fly 8 startup error 2 41
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

733 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