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:
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.
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..
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++
i just add write permission to "logs" folder and it works for me
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 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