I am trying to change the location of the file depending on the OS type using SL4J 2.5. Looking up at other Stack overflow questions here and here. I came up with the following:
log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" name="JCal">
<Appenders>
<File name="MyFile" fileName="${sys:JCalEnv}">
<PatternLayout>
<Pattern>%d %p [%t] %c{2} - %m%n</Pattern>
</PatternLayout>
<!--<HTMLLayout>-->
<!--<title>JStreamer-log</title>-->
<!--</HTMLLayout>-->
</File>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} %-5level %logger{36}.%M() @%L - %msg%n}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=black, DEBUG=green bold, TRACE=blue}"/>
</Console>
<Async name="Async">
<AppenderRef ref="MyFile"/>
</Async>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
<AppenderRef ref="Async"/>
</Root>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="Async"/>
</Root>
</Loggers>
</Configuration>
Test.java
public class Test extends Application {
static {System.setProperty("JCalEnv", getUserAppDirectory());}
public static final Logger logger = LogManager.getLogger();
public static double JAVA_VERSION = getVersion();
public static void main(String[] args) {
launch(args);
}
static String getUserAppDirectory() {
General g = new General();
if (g.isMacOS()) {
return System.getProperty("user.home") + "/.JCal/logs/JCal-log.log";
}
else {
return System.getProperty("user.home") + "/JCal/logs/JCal-log.log";
}
}
}
When ever I run the file, LOG4J creates ${sys/JCalEnv} file with logs in it. Could anyone tell me how could I give its location and the name depending on the OS type?
Note: There is . folder for OS X file.