Reputation: 9765
Here is my log4j.properties file
# Define the root logger with appender file
log = D:/workspaces/Abhishek/Automation/MOPS/logs
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
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=%d{ABSOLUTE} %5p - %m%n
This does job for me only problem is the absolute path i have used. I want to use relative path now.
Below is my folder structure
--src
--com
--log4j.properties
--logs
--log.out file
So my logs folder is outside the src folder where log4j.properties is situated?
How can i define relative path in such case. In case of jsp's we do it like ../webpages/page.jsp
.
How can it be achieved here ??
Upvotes: 1
Views: 12983
Reputation: 1
On Linux with Tomcat and webapps this works:
log4j.appender.file.File=./logs/your.log
It's in /your/tomcat/webapps/your_app.war/WEB-INF/classes/log4j.properties
And it puts the log file in /your/tomcat/logs/
folder.
P.S. As I found out recently, it's not a good idea to use relative paths in this case. Because you can run the tomcat from different folders, not just tomcat_home/bin/ So, the best answer is by Piaget Hadzizi
Upvotes: 0
Reputation: 835
I had the same problem and I simply changed the following line
log4j.appender.file.File=logs\\myLogFile.log
And it worked fine relative to the current working directory
Upvotes: 2
Reputation: 2488
you can pass dynamic value like this
{logfileLoc}/logs/file.log.
in your case you want in the project folder itself so can have -D (java argument or equivalent) param like -D logfileLoc =D:/workspaces/Abhishek , and you can access with variable logfileLoc
. and consider changing this value for different environments.
Upvotes: 3