In my log4j2.xml file, I get the complete path of the logfile by passing a system property
-Dlogfilename=/home/user/logs/server
Log4j2 configuration:
<Property name="logFile">${sys:logfilename:-/home/user/logs/server}</Property>
As an added requirement, I need to get the name of the log file from the above property and I cannot pass a new system property. How can I get just the name of the file from the complete path? I dont have any experience with XML other than its use for data transport.
You're using the System Properties Lookup incorrectly. You should specify the lookup and the key you wish to look up like this:
${sys:logfilename}
Here's a simple example:
Here is the log4j2.xml config file:
When I run this code with the following JVM parameter:
it generates a file with the name "myFile.log" and the file contains the following output: