This discussion is archived
9 Replies Latest reply: Jan 3, 2013 3:32 PM by EJP RSS

log4j:ERROR setFile(null,true) call failed.

mjmjava Newbie
Currently Being Moderated
Hello
I have Log4j.properties

log4j.rootCategory = DEBUG, file ,ImportFileAppender , console

log4j.appender.stdout.threshold = ERROR
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p [%t] %c - %m%n

log4j.appender.file.threshold = DEBUG
log4j.appender.file.File = ${qtl.log.location}
log4j.appender.file.MaxFileSize = 10MB
log4j.appender.file.MaxBackupIndex = 10
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern =%-5p|%-80m|%d%n

log4j.appender.ImportFileAppender.threshold = DEBUG
log4j.appender.ImportFileAppender.File = ${qtl.log.import}
log4j.appender.ImportFileAppender = org.apache.log4j.RollingFileAppender
log4j.appender.ImportFileAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.ImportFileAppender.layout.ConversionPattern = %-5p|%-80m|%d%n


and i am giving ${qtl.log.location} through java file like this
private static String LOG_4J_PROPERTY_FILE = "/src/com/impact/qtl12/commons/log4j.properties";

logFileName     = "log-" + new SimpleDateFormat("yyyyMMdd-hhmm").format(new Date()) + ".log";
          logFilePath = dirString + "\\" + logFileName;;

System.setProperty("qtl.log.location", logFilePath); //replacing ${qtl.log.location} by the logFilePath in log4j.properties String directory = System.getProperty("user.dir");
PropertyConfigurator.configure(directory + LOG_4J_PROPERTY_FILE);


when i run my program i get error of this type


log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException:
     at java.io.FileOutputStream.openAppend(Native Method)
     at java.io.FileOutputStream.<init>(Unknown Source)
     at java.io.FileOutputStream.<init>(Unknown Source)
     at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)
     at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:165)
     at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)
     at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)
     at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:132)
     at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:96)
     at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:654)
     at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:612)
     at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:509)
     at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:415)
     at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:316)
     at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:324)
     at com.impact.qtl12.imports.UI.CSVFile.QTL.main(QTL.java:964)
log4j:ERROR setFile(null,true) call failed.

Edited by: Mayur Mitkari on Jan 2, 2013 12:53 AM

Edited by: Mayur Mitkari on Jan 2, 2013 12:54 AM

Edited by: Mayur Mitkari on Jan 2, 2013 12:55 AM
  • 1. Re: log4j:ERROR setFile(null,true) call failed.
    EJP Guru
    Currently Being Moderated
    I would say the directory containing the target file doesn't exist.
  • 2. Re: log4j:ERROR setFile(null,true) call failed.
    mjmjava Newbie
    Currently Being Moderated
    I checked it out the directory exists and file also resides in the same directory , also i am getting, created log file when i am running the application

    Edited by: Mayur Mitkari on Jan 2, 2013 4:40 AM
  • 3. Re: log4j:ERROR setFile(null,true) call failed.
    gimbal2 Guru
    Currently Being Moderated
    Mayur Mitkari wrote:
    I checked it out the directory exists
    Really? You have a directory 'src' in the root of your filesystem?
    /src/com/...
    EDIT: never mind, moving along, I missed a bit of code there... In my own defense, use \
     formatting tags to make it slightly more inviting to read it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  • 4. Re: log4j:ERROR setFile(null,true) call failed.
    mjmjava Newbie
    Currently Being Moderated
    i try to load it from bin folder , but then also it was throwing same error
  • 5. Re: log4j:ERROR setFile(null,true) call failed.
    gimbal2 Guru
    Currently Being Moderated
    Mayur Mitkari wrote:
    i try to load it from bin folder , but then also it was throwing same error
    Sorry, I missed a bit of code so I was barking up the wrong tree.

    I don't know what's going on here, I've never had issues with log4j 1.12+ and using a log4j.xml file in stead of a properties file. Granted, I never use parameterized paths in the config file, I just hardcode the path in the configuration file itself. If you do that too, does the problem go away?
  • 6. Re: log4j:ERROR setFile(null,true) call failed.
    mjmjava Newbie
    Currently Being Moderated
    Hello
    Does anybody has solution for this thread , if you have please help

    Regards
    Mayur Mitkari
  • 7. Re: log4j:ERROR setFile(null,true) call failed.
    EJP Guru
    Currently Being Moderated
    Maybe you are setting the system property too late, so it is still null when the failing code executes. You can verify that with a println() easily enough.
  • 8. Re: log4j:ERROR setFile(null,true) call failed.
    mjmjava Newbie
    Currently Being Moderated
    Hello EJP , you are right

    but there is problem
    In my application , i am creating log file on the click of different function, now when i am setting all the statement in constructor of my class like this

    System.setProperty("qtl.log.location", logFilePath);
                   System.setProperty("qtl.log.create", createLogFilePath);
                   System.setProperty("qtl.log.rollBack", rollbackLogFilePath);
                   System.setProperty("qtl.log.validate", validateLogFilepath);
                   System.setProperty("qtl.log.import", importLogFilePath);

    and on the click of different functional buttons i am calling this seperately

    PropertyConfigurator.configure("log4j.properties");

    so all log files are created when i am launching my application with same content so wahat can i do in this case

    Regards
    Mayur Mitkari
  • 9. Re: log4j:ERROR setFile(null,true) call failed.
    EJP Guru
    Currently Being Moderated
    I gather that you want to be able to change the log file location dynamically. However you still have to start off with a legal value, rather than null. You need to set something into that system property before any logging or log initialization takes place.

    Alternatively you should just review the requirement. It's pretty unusual.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points