Solved

log4j xml config file won't work

Posted on 2014-02-05
6
869 Views
Last Modified: 2014-02-05
I am trying to set up log4j to run based on an xml config file but I keep getting an error:

I'm setting the file but it can't find it... I've uploaded my xml file and my java class - can anyone tell me what I've missed?

log4j: reset attribute= "false".
log4j: Threshold ="null".
log4j: Class name: [org.apache.log4j.RollingFileAppender]
log4j: Setting property [file] to [ODSLoader2.log].
log4j: Setting property [maxFileSize] to [1KB].
log4j: Setting property [maxBackupIndex] to [5].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss,SSSZ} %-5r %-5p [%c{1}] (%t:%x) %m%n].
log4j: setFile called: ODSLoader2.log, true
log4j: setFile ended
log4j: Adding appender named [app] to category [root].
log4j:ERROR No output stream or file set for the appender named [null].
log4j.xml
ODSLogger3.java
0
Comment
Question by:boukaka
[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
  • 3
  • 3
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39836906
Firstly, could you clarify what you think the problem is? Which file are you talking about for instance, the log output file?
0
 

Author Comment

by:boukaka
ID: 39837008
First of all, I have since had to change the xml because the filename was wrong but the issue remains the same.

It doesn't seem to be seeing the log output file. If I hardcode everything programmatically (which works beautifully), the code looks like below. When I changed it to point to the xml, the error seems to say that the RollingFileAppender doesn't have an output file.

 So I changed this code
RollingFileAppender app = new RollingFileAppender(layout, "./logs/ODSLogger.log");

To this code
RollingFileAppender app = new RollingFileAppender();

And I'm trying to set the file in the xml. The error log shows that it sees the xml and is reading it but

og4j: setFile called: ./logs/ODSLogger.log, true <--- it see's it here
log4j: setFile ended
log4j: Adding appender named [app] to category [root].
log4j:ERROR No output stream or file set for the appender named [null]. <---but now it's gone?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39837062
<---but now it's gone?
Because: you don't give the Appender a name:
	  RollingFileAppender app = new RollingFileAppender();	
	  //app.setMaxFileSize("10MB");
      logger.addAppender(app);     

Open in new window


There are really two broad problems:

a. your code is schizophrenic: it's partly controlled declaratively (via log4j.xml) and partly in code. The two conflict
b. i'm wondering what the point of it is. What do you see as being gained from it, as against direct use of logging in what's actually being logged?
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:boukaka
ID: 39837119
This is my first time using log4j, what I'm trying to do is have it 100% controlled declaratively (via log4j) to avoid the need for code changes if they want to change logging parameters.

I'm not sure what you mean by not giving the RollingFileAppender a name? Haven't I called it "app" in the code below?

RollingFileAppender app = new RollingFileAppender();

How can I modify what I have to do what I'm trying to accomplish?
0
 

Author Comment

by:boukaka
ID: 39837147
Oh wait, when you said my code was schizophrenic that pointed out that I needed to remove the  logger.setAdditivity(false); from my .java, now it's working perfectly.

Thanks,
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39837166
Haven't I called it "app" in the code below?
No. That's the name of a variable. I'm referring to its name attribute

Oh wait, when you said my code was schizophrenic that pointed out that I needed to remove the  logger.setAdditivity(false); from my .java
Well that's not quite in the same vein but it IS a problem, yes

There's no real problem in achieving full declarative operation. Just make sure you read the docs carefully ;)
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

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…
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…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

734 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