File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes log4j:ERROR Could not read configuration file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "log4j:ERROR Could not read configuration file" Watch "log4j:ERROR Could not read configuration file" New topic
Author

log4j:ERROR Could not read configuration file

Ameya Thakur
Ranch Hand

Joined: Feb 04, 2004
Posts: 43
Hi Everyone!!

When i do

Properties myProp = ResourceUtils.getResourceAsProperties("com.cs.local.properties/log4j.properties");
org.apache.log4j.PropertyConfigurator.configure(myProp);

I am able to read the log4j.properties.

But when i do

org.apache.log4j.PropertyConfigurator.configure("com.cs.local.properties/log4j.properties");

I get the following Error... I just wanted to know the difference between these two approaches in loading the log4j.properties as when i do it with the First Approach.... i can write any invalid class appenders in log4j.properties and it still not validates the log4j.properties which is I feel personally...

When i try to do the same with the second approach..some thing strange which came to my notice

log4j:ERROR Could not find value for key log4j.appender.Fileww
log4j:ERROR Could not instantiate appender named "Fileww".
log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:123)
at java.io.FileInputStream.<init>(FileInputStream.java:86)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:306)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:324)
at com.cs.services.logging.Log4JEventLogger.init(Log4JEventLogger.java:68)
at com.cs.services.logging.Log4JEventLogger.main(Log4JEventLogger.java:61)
log4j:ERROR Ignoring configuration file [log4j.properties].



I was just trying to test with "ww"...and after validating that how comes it throws an Error file not found....

I am trying to resolve this Issue since yesterday if any body can help me out with this that would be great



log4j:ERROR Could not read configuration file[com.cs.local.properties/log4j.properties].
java.io.FileNotFoundException: com.cs.local.properties\log4j.properties (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:123)
at java.io.FileInputStream.<init>(FileInputStream.java:86)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:306)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:324)
at com.cs.services.logging.Log4JEventLogger.init(Log4JEventLogger.java:68)
at com.cs.services.logging.Log4JEventLogger.main(Log4JEventLogger.java:61)
log4j:ERROR Ignoring configuration file [com.cs.local.properties/log4j.properties].


Thanks
Ameya
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
I'm not familiar with ResourceUtils.getResourceAsProperties, but it looks like that is looking for something on the classpath and the PropertyConfigurator.configure() is looking not on classpath, rather a relative path. Relative paths are not so great to use in a web app.

Did you try putting log4j.properties into WEB-INF/classes and just letting log4j find it?
Ameya Thakur
Ranch Hand

Joined: Feb 04, 2004
Posts: 43
Hi Carol!!
Nice to see your reply...
ResourceUtils.getResourceAsProperties is our own class which is use for reading the property files.
We are working on websphere and everything goes into ejbmodule..

I know that this issue is w.r.t classpath...but it should be uniform right...also if you notice at the error carefully you would get some contradicting messages

Following are the first 4 lines of the Error.

1st line say's Could not find value for key log4j.appender.Fileww
which mean's it read log4j.properties.

3rd & 4th Line error drives me crazy ..if it is reading from a log4j.properties file how can it throw file not found exception


1)log4j:ERROR Could not find value for key log4j.appender.Fileww
2)log4j:ERROR Could not instantiate appender named "Fileww".
3)log4j:ERROR Could not read configuration file [log4j.properties].
4)java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified)


Thanks for your patience in going through this mail
Regards,
Ameya
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Looks like I answered too quickly.

Not sure I understand the problem then. Is there a problem or you are just curious?

Could you show your properties file and code? Why would you want to include an invalid appender and what do you mean by that? Is your properties file on the classpath?
Ameya Thakur
Ranch Hand

Joined: Feb 04, 2004
Posts: 43
Sorry that I am replying a bit late.....It is a problem and I am curious to know about it , ie why is it throwing Class Not Found Exception after reading from a file.....

I wanted to include Invalid appenders just to check whether my log4j.properties is been properly validated and loaded.Log4j.properties is present in the classpath of the project

For time been My Log4j.properties is the simplest you would find

log4j.rootLogger=DEBUG,File

log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=CoreConnectLogs.log
log4j.appender.File.DatePattern='.'yyyy-MMM-dd
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.append=true

log4j.appender.File.layout.ConversionPattern = %d | %5p | [%t] | %c:%M(%L) | %m %n


The code from where I am trying to acess the code is
1st Approach
PropertyConfigurator.configure("com.cs.local.properties/log4j.properties");

and
2nd Approach
Properties myProp = ResourceUtils.getResourceAsProperties("com.cs.local.properties/log4j.properties");
System.out.println(myProp);
PropertyConfigurator.configure(prop);

over here my SOP reads from the log4j.properties and prints it..but does not validates it.....


so I was just curious to know about the same

Thanks & Regards,
Ameya
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
If log4j.properties is in your classpath AND you call PropertyConfigurator.configure() with that log4j.properties then it will try to configure using that properties file twice. That is probably not something you want. If you don't want it loaded automatically change the name.

Are you already running with log4j.debug set? If not I'd recommend putting log4j.debug=true in your properties file.

Not sure why you get different reactions to your invalid appender. I've never loaded the properties and then passed that to the configure method. Actually I've only used the configure methods while playing around with log4j or when trying out examples.

I don't see invalid appenders in your properties file.
Ameya Thakur
Ranch Hand

Joined: Feb 04, 2004
Posts: 43
I am not putting log4j.debug=true, I would just try debug=true and then check it out.

I have removed the invalid appenders and then sent it acorss to you....

Currently i am not facing an issue with the file not found exception as I have created a test Project and working on that as i have lot may things to do using log4j... I have done JDBCAppenders which is good.

Also I whave a scenario over here I know log4j provides a feature where-in you can specify different Logging Level for different classes

i.e ClassA is been logged using Debug Mode and ClassB is been logged using Error mode...
Ameya Thakur
Ranch Hand

Joined: Feb 04, 2004
Posts: 43
Hi Carol!!!

private static Logger theClassLogger;

public void logEvent(int aEventLogLevel,int aEventCategory,int aEventId,String aEventText,String aEventDetails,Object aAssociatedObject,Object aObjectInstance,Throwable aThrowable){

String logName;
if (aObjectInstance == null) {
logName = "BaseObject";
}
else {
logName = aObjectInstance.getClass().getName();
}
theClassLogger = Logger.getLogger(logName+".class");
switch (aEventLogLevel) {
case 0 :
theClassLogger.debug(LOG_LEVEL_DEBUG, aEventCategory, aEventText);
break;
case 3 :
theClassLogger.trace(LOG_LEVEL_TRACE,aEventCategory, aEventText);
break;
default :
theClassLogger.debug(LOG_LEVEL_DEBUG, aEventCategory, aEventText);


Since we are having our Own Logging mechanism and we wish to move to LOG4J with minimal changes this is the approach which i thought would be right.

But when i try to implement this at the runtime I get an Error stating
log4j:WARN No appenders could be found for logger (com.cs.applications.corconnect.CorConnectServlet.class).
log4j:WARN Please initialize the log4j system properly.


So would you kindly suggest or give me some more inputs on the same

Thanks & have a great weekend Ahead
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Sounds like it is not finding your properties file. Are you using the debug flag?

If you are still having problems with that, try something really simple like just running a java class that uses your logger. See what the output looks like when it is being configured. Look for that in your real situation.

If you are having issues specific to your application server, you may get more help in your server's forum.

FYI, when asking log4-specific questions try the Other Open Source Projects rather than Application Frameworks since it specifically mentions log4j


Other Open Source Projects
Jakarta Projects (like Log4j etc.), SourceForge and other Open Source Projects (Ant has its own forum)
Ameya Thakur
Ranch Hand

Joined: Feb 04, 2004
Posts: 43
Hi Carol!!

Ya I wanted to move from this forum to Other Open Source Projects, I gues this can be only done by the moderator.

Anyways I had tried using

package com.cs.test;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;

import com.cs.core.BaseObject;

/**
* @author athakur
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class TestLog4jProperties extends BaseObject {
/**
*
*/
public TestLog4jProperties() {
super();
// TODO Auto-generated constructor stub
}
private static Logger theClassLogger;
public static void main(String[] args) throws Exception{
//org.apache.log4j.PropertyConfigurator.configure("com.cs.local.properties/log4j.properties");
//theClassLogger = Logger.getLogger(TestLog4jProperties.class);
//theClassLogger.debug("Hey This is Test I am in Log4JEventLogger ============================>222222222");
//System.err.println("Afterlogging");
try {

TestLog4jProperties obj = new TestLog4jProperties();
obj.a();
}
catch (Exception e) {
// TODO: handle exception
}

}
void a(){
System.err.println("11");
log( LOG_LEVEL_DEBUG, 1, "DEBUG ",this );
log( LOG_LEVEL_ERROR, 2, "DEBUG " ,this);
log( LOG_LEVEL_CRITICAL ,3, "CRITICAL " ,this);
log( LOG_LEVEL_WARNING ,4, "WARNING " ,this);
log( LOG_LEVEL_TRACE ,5000, "TRACE" ,this);
log( LOG_LEVEL_DETAIL ,5000, "DETAIL ",this );
System.err.println("22");
log(LOG_LEVEL_DEBUG, 5000, "DEBUG",this );
System.err.println("33");
try {
String a ="Ameya";
int b=0;
int c=5/b;
System.err.println("Erro is "+c);
}
catch (Exception e) {
System.err.println("44");
log(LOG_LEVEL_DEBUG, 5000, "DEBUG",e );
System.err.println("55");
log(LOG_LEVEL_DEBUG, 5000, "This is Event Text","This is Event Details", this,e);
System.err.println("66");
log(LOG_LEVEL_DEBUG, 5000, "This is Event Text","This is Event Details",e);
}
System.err.println("77");
log(LOG_LEVEL_DEBUG, 5000, "This is Event Text","This is Event Details", this);
//log( LOG_LEVEL_TRACE, 500, "Trace Mode" );
//log( LOG_LEVEL_CRITICAL, 500, "Critical" );
}
}



My Log4j.properties goes as follow


log4j.rootCategory=DEBUG, R, O
#Stdout
log4j.appender.O=org.apache.log4j.ConsoleAppender
#File
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log4j.log
# Control the maximum log file
sizelog4j.appender.R.MaxFileSize=100KB
# Archive log files (one backup file here)
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.O.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n
log4j.appender.O.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n




My Log4Logger class

public void logEvent(int aEventLogLevel,int aEventCategory,int aEventId,String aEventText,
String aEventDetails,Object aAssociatedObject,Object aObjectInstance,Throwable aThrowable){
String logName;
if (aObjectInstance == null) {
logName = "BaseObject";
}
else {
logName = aObjectInstance.getClass().toString();//.getName();
System.err.println("Log Name "+logName);
}
theClassLogger = Logger.getLogger(logName);

switch (aEventLogLevel) {
case 0 :
log( LOG_LEVEL_DEBUG, aEventCategory, aEventText);
break;
case 3 :
theClassLogger.debug("This is a Test"+aEventText);
break;
case 4 :
theClassLogger.debug("Fatal "+aEventText);
break;
case 5 :
theClassLogger.trace("Hey I am In Trace and My Log Level is"+LOG_LEVEL_TRACE+ "-"+aEventText);
break;
case 6 :
theClassLogger.info("aEventText "+aEventText);
break;
case 7 :
theClassLogger.info("aEventText "+aEventText);
break;
case 8 :
break;
case 9 :
theClassLogger.fatal("Fatal "+aEventText);
break;
case 10 :
theClassLogger.fatal("Fatal "+aEventText);
break;
case 11 :
break;
default :
theClassLogger.debug("This is a Been Defaulted Test"+aEventText + "-" +aEventLogLevel);
break;
}
}
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Please use the code tags (see Instant UBB Code button "CODE") so your code will be a little more readable.

I don't see a new question, or anything about why you are showing a bunch of code and properties other than that you tried it.
 
 
subject: log4j:ERROR Could not read configuration file