LOG4J2 configuration of log relative paths
The path configuration for the logs in the previous project is configured with the following:
<file name= "Log" filename= "Log/test.log" append= "false" >
<patternlayout pattern= "%d{hh:mm:ss. SSS}%-5level%class{36}%l%M-%msg%xex%n "/>
</File>
The log document for this configuration is archived when you run the program's top-level path (for example: C: or D:), I need to configure the relative path to the logs file under Run program path. Check the online two solutions, we give the method are: http://blog.csdn.net/whoopee/article/details/851416 the same, but I use a log4j2 non-Web project, try to read the environment variable several times, Incorrect strings or assignments are all configured incorrectly. Finally, there is no way, only to view official documents, the following is the official document of the Variable value table:
Discover that LOG4J2 does have its own rules for reading variables, a brief introduction to several commonly used date--can be inserted into the current date/time in a specific format env--can read the system's environment variable Jvmrunargs--can read the JVM when the runtime parameters set at startup, But the parameters of the main function cannot be read, and the SYS is not used on the Android system-the properties of the system properties are read, basically these parameters are sufficient.
Now let's talk about the configuration workaround for resolving log relative paths, set myapp_home =%~dp0 (set the current directory as the root) in the Option.bat batch file of the startup options, and then reference the variable in the Log4j2.xml file:
<file name= "Log" filename= "${env:myapp_home}/log/test.log" append= "false" >
<patternlayout pattern= "%d {HH:mm:ss. SSS}%-5level%class{36}%l%M-%msg%xex%n "/>
</File>
OK to solve.