Meaningless Drivel is fun!*
The moose likes Tomcat and the fly likes DailyRollingFileAppender & Servlets with Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "DailyRollingFileAppender & Servlets with Tomcat" Watch "DailyRollingFileAppender & Servlets with Tomcat" New topic
Author

DailyRollingFileAppender & Servlets with Tomcat

Ra Carter
Ranch Hand

Joined: Jul 30, 2005
Posts: 96
logging to the console works for me using log4j and servlets but when i make a slight modification to use a DailyRollingFileAppender I receive a security exception in tomcat's log files:


log4j:ERROR Could not create an Appender. Reported error follows.
java.security.AccessControlException: access denied (java.io.FilePermission mylog.txt write)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)


the rolling file appender seems to work from normal console apps. my config file looks like this:


i guess this is really a tomcat question but also.. if that were to work, what folder would the mylog.txt file be stored in? where can servlet's read and write from?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It sounds like your running Tomcat with a security manager.
If so, you may need to alter your security policy to allow writes to the specified file or diretory.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ra Carter
Ranch Hand

Joined: Jul 30, 2005
Posts: 96
ok, so i tried editing the catalina.policy file by appending this to the end:



and then i'll issue a command like:
sudo /etc/init.d/tomcat5.5 restart

at which i point i notice that the line i wrote to the catalina.policy file has been erased anyway. i obviously don't know what i am doing here, any tips for me?

also is there anyway to use wildcards for this stuff? as in ${catalina.home}/**/log4j*.jar ?
[ July 07, 2007: Message edited by: ra carter ]
ajse ruku
Ranch Hand

Joined: May 06, 2005
Posts: 194
pls try placing mylog.txt inside tomcat>>logs folder
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by ra carter:




Its definitely a issue with the policy file.Change it as mentioned by Ra Carter.However try using a narrower permission to avoid AllPermission.

policy file you can fine in Tomcat's conf directory.

One more thing you might try is grant the permission to the file that is using log4j , not to the log4j jar itself.


Rahul Bhattacharjee
LinkedIn - Blog
 
GeeCON Prague 2014
 
subject: DailyRollingFileAppender & Servlets with Tomcat