My app outputs some files to dynamically created directory with a name determined by System.currentTimeMillis() every time it runs.
Tried the following solution:
<File name="File" fileName=".\xxx\${sys:log4j2.saveDirectory}\test.log" immediateFlush="false" append="false">\
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
In java code I call:
String path = Long.toString(System.currentTimeMillis());
System.setProperty("log4j2.saveDirectory", path);
but this does not work, as I get FileNotFoundException
. What is a way to tell log4j2 to log in this kind of dynamically created folder?
Problem solved. I was calling
System.setProperty("log4j2.saveDirectory", path);
after logger initialization. Solution is to do it before initializing logger or set default path.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.