Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top