JASIG CAS: How do I change where log files are written to?

Belmin Fernandez picture Belmin Fernandez · Feb 29, 2012 · Viewed 8.2k times · Source

I know very little about Java, let alone JASIG CAS.

We are trying to implement CAS on our CentOS 6 server. We are getting the following errors:

java.io.FileNotFoundException: cas.log (Permission denied)
[...snip...]
java.io.FileNotFoundException: perfStats.log (Permission denied)

After some investigation, it seems like tomcat6 is trying to write the log files in its home directory (/usr/share/tomcat6/). I was able to determine this by chown tomcat: /usr/share/tomcat6 and then, after a restart, the log files were created in that directory.

All the other logs though are written to /usr/share/tomcat6/logs which is a symlink to /var/log/tomcat6.

I want to know how do I reconfigure CAS to write these 2 log files to a different directory /usr/share/tomcat6/logs)?

Answer

Mike E picture Mike E · Mar 1, 2012

Assuming you have a recent version of CAS, it uses log4j for logging, and you can find the log4j configuration in

$CATALINA_BASE/webapps/cas-server-webapp-VERSION/WEB-INF/classes/log4j.xml

For a standard Tomcat install under CentOS, $CATALINA_BASE would be /usr/share/tomcat.

If your log4j configuration has not been changed, you'll find an appender named "cas" near the top of the file which is responsible for creating cas.log. It looks like this:

<appender name="cas" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="cas.log" />
    <param name="MaxFileSize" value="512KB" />
    <param name="MaxBackupIndex" value="3" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %p [%c] - %m%n"/>
    </layout>
</appender>

Further down you'll find another appender named "fileAppender", which creates the perfStats.log file.

<appender name="fileAppender" class="org.apache.log4j.FileAppender">
    <param name="File" value="perfStats.log"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%m%n"/>
    </layout>
</appender>

See how the value for the File parameters is just a file name with no directory specified? The log files therefore get created in the $CATALINA_BASE directory. To get them into the Tomcat logs directory where you want them, just change the values to logs/cas.log and logs/perfStats.log.

Note that CAS only reads the log4j config at startup, so once you've made the change you'll have to either undeploy and redeploy CAS or bounce Tomcat for it to take effect.