I know my title is not very barely, I try to be more specific here. I'm using log4j2, And up to now my log folder was: "C:\log"
I want to change the root drive("C:") to where the app installed.
For example: If the jar file located in "d:\apps\jar.jar", The log path will be "d:\log" and if the jar file located in "c:\apps\jar.jar", The log path will be "c:\log"
I tried to change the line in my log4j2.xml (Below) to:
fileName="${myapp.data.dir}/log/log_${date:dd-MM-yyyy_HH-mm-ss}.csv">
And call this function before i initial the logger:
private static void initialLog() {
Path dllPath = Paths.get(System.getProperty("user.dir"));
String driveLetter = dllPath.getRoot().toString().replace("\\", "");
System.setProperty("myapp.data.dir", driveLetter);
}
But its not work. Any Idea?
My Old log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{dd/MM/yyyy HH:mm:ss:SSS} %p %c{1.} %m%n"/>
</Console>
<File name="log"
fileName="C:/log/log_${date:dd-MM-yyyy_HH-mm-ss}.csv">
<PatternLayout pattern="%d{dd/MM/yyyy,HH:mm:ss},%p,%m%n"
header="Date,Time,Type,Message%n" />
<Filters>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="NEUTRAL" />
<ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL" />
<ThresholdFilter level="debug" onMatch="DENY" onMismatch="NEUTRAL" />
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL" />
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL" />
</Filters>
</File>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="log" />
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>