[java] Error: "setFile(null,false) call failed" when using log4j

I have added log4j.properties file in source folder of project but I am still getting a log4j:error.

Here is my Log4j.properties file:

    .rootCategory=DEBUG, R, O
    # Stdout
    log4j.appender.O=org.apache.log4j.ConsoleAppender
    log4j.appender.O=log44j.log
    # File
    log4j.appender.R=org.apache.log4j.RollingFileAppender
    log4j.appender.R.File=log4j.log

    # Control the maximum log file size
    log4j.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

    # Define the root logger with appender file
    logDir = ../logs
    log4j.rootLogger = DEBUG, FILE

    # Define the file appender
    log4j.appender.FILE=org.apache.log4j.FileAppender
    log4j.appender.FILE.File=logs/${file.name}
    log4j.appender.FILE.Append=false

    # Define the layout for file appender
    log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.FILE.layout.conversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

    log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout

Here is the Java exception that I am getting:

log4j:ERROR setFile(null,false) call failed.
java.io.FileNotFoundException: logs (Access is denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
    at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
    at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
    at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:809)
    at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
    at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:547)
    at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
    at org.apache.log4j.Logger.getLogger(Logger.java:104)
    at lib.Dashboard.Reports.<init>(Reports.java:34)
    at testcases.AmazonDashboard.TC_DB17.main(TC_DB17.java:54)
AmazonDashboardTC_DB17Exception in thread "main" java.lang.NullPointerException
    at testcases.AmazonDashboard.TC_DB17.main(TC_DB17.java:131)

Please let me know, how to resolve this exception, as I have tried placing my properties file in root folder and now I have placed in source folder but in both cases I got the above exception.

This question is related to java file logging log4j

The answer is


This is your config :

log4j.appender.FILE.File=logs/${file.name}

And this error happened :

java.io.FileNotFoundException: logs (Access is denied)

So it seems that the variable file.name is not set, and java tries to write to the directory logs.


You can force the value of your variable ${file.name} calling maven with this option -D :

mvn clean test -Dfile.name=logfile.log

To prevent this isue I changed all values in log4j.properties file with directory ${kafka.logs.dir} to my own directory. For example D:/temp/...


if it is window7(like mine), without administrative rights cannot write a file at C: drive

just give another folder in log4j.properties file

Set the name of the file

log4j.appender.FILE.File=C:\server\log.out you can see with notepad++


Please changes your log file location to another drive. it will work.

this happen's the permission of creating log file.


Have a look at the error - 'log4j:ERROR setFile(null,false) call failed. java.io.FileNotFoundException: logs (Access is denied)'

It seems there's a log file named as 'logs' to which access is denied i.e it is not having sufficient permissions to write logs. Try by giving write permissions to the 'logs' log file. Hope it helps.


I suspect that the variable ${file.name} is not substituted correctly. As a result, the value of log4j.appender.FILE.File becomes logs/. As such, Java tries to create a log file named logs/, but probably it is an existing directory, so you get the exception.

As a quick remedy, change the log4j.appender.FILE.File setting to point to file by absolute path, for example /tmp/mytest.log. You should not get an exception.

After that you can proceed to debugging why ${file.name} is not replaced correctly in your runtime environment.


this error is coming because of appender file location you have provided is not reachable with current user access.

Quick Solution, change the log4j.appender.FILE.File setting to point to file using absolute path which location is reachable to the current user you have logged in, for example /tmp/myapp.log. Now You should not get an error.


I had the exact same problem. Here is the solution that worked for me: simply put your properties file path in the cmd line this way :

-Dlog4j.configuration=<FILE_PATH>  (ex: log4j.properties)

Hope this will help you


Try executing your command with sudo(Super User), this worked for me :)
Run : $ sudo your_command
After than enter the super user password. Thats All..


i just add write permission to "logs" folder and it works for me

add write permission


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to file

Gradle - Move a folder from ABC to XYZ Difference between opening a file in binary vs text Angular: How to download a file from HttpClient? Python error message io.UnsupportedOperation: not readable java.io.FileNotFoundException: class path resource cannot be opened because it does not exist Writing JSON object to a JSON file with fs.writeFileSync How to read/write files in .Net Core? How to write to a CSV line by line? Writing a dictionary to a text file? What are the pros and cons of parquet format compared to other formats?

Examples related to logging

How to redirect docker container logs to a single file? Console logging for react? Hide strange unwanted Xcode logs Where are logs located? Retrieve last 100 lines logs Spring Boot - How to log all requests and responses with exceptions in single place? How do I get logs from all pods of a Kubernetes replication controller? Where is the Docker daemon log? How to log SQL statements in Spring Boot? How to do logging in React Native?

Examples related to log4j

No log4j2 configuration file found. Using default configuration: logging only errors to the console How to stop INFO messages displaying on spark console? What is log4j's default log file dumping path How to give environmental variable path for file appender in configuration file in log4j No appenders could be found for logger(log4j)? SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". in a Maven Project log4j:WARN No appenders could be found for logger (running jar file, not web app) Error: "setFile(null,false) call failed" when using log4j java.lang.ClassNotFoundException: org.apache.log4j.Level How can I create 2 separate log files with one log4j config file?