Following are the steps which could be used as a configuration for log4j:-
(1) In log4j.xml define variable as ${variable}:
<appender name="FILE" class="org.apache.log4j.FileAppender"> <param name="File" value="${logfilename}.log" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d::[%t]::%-5p::%c::%x - %m%n" /> </layout> </appender>
(2) Then make sure you set the system property when you start your JVM such as:
java -Dlogfilename=VinayFileLogger com.vinay.myApplication
(3) Alternatively, you can set the system property in code so long as you do it before you create a logger (this is useful if you want your PID in your logs for instance). Such as:
System.setProperty(“logfilename”, ” VinayFileLogger “);
(4) Once that is set you can go ahead and get your loggers as normal and they will log to the dynamic file
How to set VM arguments in Tomcat
(1) Right Mouse Click on Tomcat Server >> Configure Server Connector
(2) Select Preference >> Tomcat >> Tomcat x.x >> JDK
(3) Now, set the VM arguments as per the snapshot.