Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I obtain this FileNotFoundException when I try to use log4j to write into a file?

I am absolutly new using log4j and I have the following problem.

I am trying to print the logging line into a file named log.out.

So I create the following log4j.properties configuration file:

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

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

The problem is that, when I perform my application and when it incurs in a logging operation, something like this:

logger.debug("INTO main()");

I obtain the following exception into the console (the error message related to the log.out file is access denied (in italian Accesso negato):

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: \log.out (Accesso negato)
        at java.io.FileOutputStream.open(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.FileAppender.activateOptions(FileAppender.java:163)
        at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:2
56)
        at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.j
ava:132)
        at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.j
ava:96)
        at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigura
tor.java:654)

and don't write nothing into my log.out file (that I have created manually). This log.out file is at the same level of the performed jar file that represent my application.

Why? What am I missing? How can I solve this issue?

Tnx

like image 415
AndreaNobili Avatar asked Mar 04 '15 15:03

AndreaNobili


People also ask

What to do for log4j in files?

To write your logging information into multiple files, you would have to use org. apache. log4j. RollingFileAppender class which extends the FileAppender class and inherits all its properties.

Where does log4j write to?

The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging.

What is the log4j error?

A common example of Log4j at work is when you type in or click on a bad web link and get a 404 error message. The web server running the domain of the web link you tried to get to tells you that there's no such webpage. It also records that event in a log for the server's system administrators using Log4j.

What is the file name for log4j?

By default, Log4j looks for a configuration file named log4j2. xml (not log4j. xml) in the classpath. You can also specify the full path of the configuration file with this system property: -Dlog4j.configurationFile=path/to/log4j2.xml.


1 Answers

I think $log is empty and it's trying to create a file on root and you are running program as a normal user. give it a check.

like image 167
Satya Nand kanodia Avatar answered Dec 17 '22 05:12

Satya Nand kanodia