Solved

log4j xml config file won't work

Posted on 2014-02-05
6
886 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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 …

626 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