GoogleSearchBox

Custom Search

Thursday, June 6, 2013

java.io.FileNotFoundException: cas.log (Permission denied) While Configuring CAS with your java Application

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: cas.log (Permission denied)

Basically you are here because you got above logs in your log files while configuring / deploying CAS for SSO (Single Sign On) functionality.

Okay! Basically the reason is simple, CAS by default is trying to create the cas.log file at a default location and it does not have adequate permission to create that file at that location.

Solution, you configure the log4j.xml file as below to point/direct log files to be generated at location/directory, which you have access rights and can give permission (using chmod) for the application to write to that directory.

For example:
I want my log files go inside my Linux server's directory : /usr/local/tomcat6-CAS/logs/cas/cas.log

So I made the changes as below:  (look for a section "<appender name="cas" class=" in log4j.xml
My Previous/Before settings related to cas was:

<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>

My After Changes :

<appender name="cas" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="/usr/local/tomcat6-CAS/logs/cas/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>


Similarly if you are getting :
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: perfStats.log (Permission denied)

Then your changes are also similar as above:

My Previous/Before settings was:

<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>

My After Changes :

<appender name="fileAppender" class="org.apache.log4j.FileAppender">
        <param name="File" value="/usr/local/tomcat6-CAS/logs/cas/perfStats.log" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%m%n"/>
        </layout>
    </appender>