0

I'm writing a java Application for Tomcat 7.

I have a bean configuration for a class that creates a log file and appends information to it.

now the question is how can I know the tomcat log directory path in bean configuration.

for now I have the following bean:

    <bean id="foo_logger" class="com.bar.LoggerBean">
            <!-- <property name="logPath" value="/path/DWHEventGenerator.log"/> -->
            <property name="logPath" value="/var/lib/tomcat7/logs/mylog.log"/>
            <property name="logLevel" value="ALL"/> <!-- ALL, FINE/R/ST, INFO, SEVERE, WARNING, OFF -->
    </bean>

what i'd like to do is instead of specify /var/log/tomcat7/log, is to specify some variable that will indicate the actual path of the logs directory of tomcat. is that possible ?

thank you.

ufk
  • 30,912
  • 70
  • 235
  • 386

1 Answers1

2

The simplest approach would be to use catalina.base from the system properties in the logPath property value

<property name="logPath" value="${catalina.base}/logs/mylog.log"/>

This property will be set by Tomcat's launch script (catalina.sh/catalina.bat) so will be available for use when Spring loads the application context file.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • You just beat me to the answer! I used `${catalina.home}` though :) I now see `${catalina.base}` would be better indeed. – drvdijk Jul 28 '13 at 15:20