Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DailyRollingFileAppender & Servlets with Tomcat

 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pls try placing mylog.txt inside tomcat>>logs folder
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic