Reputation: 33625
i am using log4j as my logging library, and i want the generated log file to be inside my web application, so following are the jars i am using:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
and following are log4j configuration:
log4j.rootLogger=DEBUG, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=mylog.log
log4j.appender.R.MaxFileSize=10000KB
log4j.appender.R.MaxBackupIndex=3
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
# Control/Limit integrated frameworks logging messages
log4j.logger.org.springframework=ERROR
Problem: when i use file system path like log4j.appender.R.File=${user.home}/mylog.log
the file is created successfully with no problems, but when trying to use a relative path like: log4j.appender.R.File=mylog.log
the file is not created.
please advise how to fix that.
Upvotes: 0
Views: 2016
Reputation: 421
Check permissions of the current working directory. Be sure that user executing the Java process has read and write access.
To determine the working directory, run this from a class in the web application context (e.g. a Servlet
or a ServletContextListener
):
System.out.println("Working Directory = " + System.getProperty("user.dir"));
Upvotes: 1
Reputation: 300
Since you mentioned a web application the current working directory would be the web container root -like TOMCAT_HOME. So the log file path will be relative to your web container and not your web-application.
Also most web-containers restrict writing files into the web application directories. There might be some configurations to do that - not sure.
Upvotes: 3