Solved

log4j xml config file won't work

Posted on 2014-02-05
6
768 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 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 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