Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

log4j xml config file won't work

Posted on 2014-02-05
6
Medium Priority
?
936 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

721 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