Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

log4j xml config file won't work

Posted on 2014-02-05
6
Medium Priority
?
968 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
  • 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 1500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:
Suggested Courses

879 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