0

I am writing a program using log4j to log exceptions or error to a log file. This is how my log4j.properties look like:

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, FILE


# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender

# Set the name of the file
log4j.appender.FILE.File=C:/Users/xxxx/Documents/Logging/log/test.log


# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true

# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug


# Set the append to false, overwrite
log4j.appender.FILE.Append=true


# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d %-5p  [%c{1}] %m %n

The code works fine but my concern is regarding the relative file path that it writes to. As you can see, I have hardcoded the file path and it wouldn't be convenient if I run this program on somebody's else PC as it will throw a FileNotFoundException

Is there a way I can standardize this relative file path to be read the log file in the same directory always so it will always be able to log into the file no matter where it is run??

Daredevil
  • 1,672
  • 3
  • 18
  • 47

0 Answers0