1

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 ??

1
  • Did you find a solution for this? I also have the same scenario (logs folder outside src). Commented Sep 20, 2015 at 3:46

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

doesnt this work in xml config file? its creating a new folder {logfileLoc} instead ..
2

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.