Search code examples
log4jwildfly-10catalina

Providing catalina.home value in wildfly server arguments


I'm using log4j for logging in my project. In log4j.xml, I'm providing the path of the logfile to be generated with the help of variable catalina.home. You can find the snippet below:

  <appender name="MyAppender1" class="org.apache.log4j.DailyRollingFileAppender">
     <param name="File" value="${catalina.home}/MyLog.log" />
     <param name="DatePattern" value="'.'yyyy-MM-dd" />
     <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="[%p] %d %c %M - %m%n"/>          
     </layout>
  </appender>

I want to provide the value of catalina.home in the arguments inside standalone.conf.bat by using value of JBOSS_LOG_DIR variable, by using this command

set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.system.pkgs=org.jboss.byteman -Dcatalina.home=%JBOSS_LOG_DIR%"

But all I'm getting is blank value in front of catalina.home as you can see in the log generated while starting the server.

-Dprogram.name=standalone.bat -Xms64M -Xmx512M -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Dcatalina.home= -Dorg.jboss.boot.log.file=D:\Softwares\wildfly_2\standalone\log\server.log -Dlogging.configuration=file:D:\Softwares\wildfly_2\standalone\configuration/logging.properties

If I'm giving a static path here instead of JBOSS_LOG_DIR variable, it is working fine.

Also, I tried to set the same to JBOSS_LOG_DIR in standalone.sh (which I commented), in the below code :

    while true; do
   if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then
      # Execute the JVM in the foreground
      eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \
        \"-Dcatalina.home="$JBOSS_LOG_DIR"\"\
         \"-Dorg.jboss.boot.log.file="$JBOSS_LOG_DIR"/server.log\" \
         \"-Dlogging.configuration=file:"$JBOSS_CONFIG_DIR"/logging.properties\" \
         #\"-Dcatalina.home="$JBOSS_LOG_DIR"\"\#
         -jar \""$JBOSS_HOME"/jboss-modules.jar\" \
         $MODULE_OPTS \
         -mp \""${JBOSS_MODULEPATH}"\" \
         org.jboss.as.standalone \
         -Djboss.home.dir=\""$JBOSS_HOME"\" \
         -Djboss.server.base.dir=\""$JBOSS_BASE_DIR"\" \
         "$SERVER_OPTS"
      JBOSS_STATUS=$?
   else
      # Execute the JVM in the background
      eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \
        \"-Dcatalina.home="$JBOSS_LOG_DIR"\"\
         \"-Dorg.jboss.boot.log.file="$JBOSS_LOG_DIR"/server.log\" \
         \"-Dlogging.configuration=file:"$JBOSS_CONFIG_DIR"/logging.properties\" \
          #\"-Dcatalina.home="$JBOSS_LOG_DIR"\"\#
         -jar \""$JBOSS_HOME"/jboss-modules.jar\" \
         $MODULE_OPTS \
         -mp \""${JBOSS_MODULEPATH}"\" \
         org.jboss.as.standalone \
         -Djboss.home.dir=\""$JBOSS_HOME"\" \
         -Djboss.server.base.dir=\""$JBOSS_BASE_DIR"\" \
         "$SERVER_OPTS"

But in this case, -Dcatalina.home itself is not getting appened in the string. Can you kindly help me where is it going wrong ? Thanks in advance


Solution

  • If you're using standalone.sh you'd need to edit the JAVA_OPTS in the standalone.conf. Not that one that ends in .bat as that is for the standalone.bat script.

    Another issue you'd have is the JBOSS_LOG_DIR is set after the standalone.conf is executed.

    One option would be to use the jboss.server.log.dir property instead of catalina.home in your log4j.xml file. The other option would be to do something like JAVA_OPTS="$JAVA_OPTS -Dcatalina.home=$JBOSS_HOME/standalone/log. However the previous option would be preferred.