Hello Jim, Use a framework like Log4j which has lots of different appenders in addition to the FileAppender and RollingFileAppender. If you really want to log to file, then provide a <context-param> for the location of the files. Then you can override that with server-specific config such as with the <Parameter> element nested in a <Context> entry for your webapp. This way, your config files in your webapp never change.
You could check out some stuff I wrote for the Barracuda project and have been submitted for inclusion in Log4j's new sandbox distribution (yet to be distributed). Here is the servlet context listener to set up and clean up log4j: http://www.barracudamvc.org/cvs/Barracuda/src/org/enhydra/barracuda/webapp/log4j/Log4jApplicationWatch.java?rev=1.4&content-type=text/vnd.viewcvs-markup Here is the custom repository selector used by the context listener: http://www.barracudamvc.org/cvs/Barracuda/src/org/enhydra/barracuda/log4j/ContextClassLoaderSelector.java?rev=1.1&content-type=text/vnd.viewcvs-markup documentation is provided in the Javadoc for the context listener as far as what to set up in your web.xml. If you have any questions, you can email me privately. Note that the context listner is smart about whether file IO is allowed to the current webapp. If so, it logs using configureAndWatch() so it sees changes to your config file. Useful for development. However, it also knows when it can't access the file system and sets things up accordingly. The only thing you have to remember is to set the appropriate appender up in your configuration file. Oh, and this allows you to put log4j.jar in a shared classloader (along with ContextClassLoaderSelector) and use it for logging all your apps without stepping on each others logger repositories. They are all separated, keyed by classloader. Jake Tuesday, February 04, 2003, 2:06:30 PM, you wrote: JC> Thanks. This answers my question, but I'm still left with the JC> impression that I'll need to go beyond the WAR format if I want to write JC> to a log or flat file DB (i.e., non-temp application file). Also, since JC> containers don't guarantee support for an unpacked WAR (are there any JC> containers that truly don't support this?), putting conf files that JC> change after deployment in the WEB-INF seems a little sketchy. At the JC> minimum, it adds the hassle of extracting and re-archiving the conf file JC> to every edit. JC> My impression is that WAR was designed around the best-practices JC> scenario of having web app instances that don't save local state to the JC> filesystem, but use a DB or some J2EE storage mechanism, for ease of JC> clustering. Such apps would probably get their conf from a JNDI resource. JC> However, I still think that the correct location for log files is JC> resolved in this scenario. Those of you using WAR along with file logs JC> -- where do you put them? JC> Thanks, JC> Jim JC> Jacob Kjome wrote: >> >> Put stuff that isn't supposed to be accessed via the web under WEB-INF. >> You can create whatever directory structures you want within that. >> >> In order to obtain access to a file under WEB-INF in a completely >> portable way, use something like... >> >> getServletContext().getResourceAsStream("/WEB-INF/myproperties.xml"); >> >> As far as writing stuff to your webapp, there is no guarantee that you >> have access to the file system other than a temporary directory >> designated for your webapp by the servlet container. You only have >> access under Tomcat because, by default, it exploded .war files to >> directory structures and then serves the directory structure. However, >> webapps can be deployed entirely from a .war file, in which case you >> can't use File IO within the application structure. I am acutally >> looking for a way to be able to write directly into an archive such as a >> .war file. If you happen on any info on that I would love to know about >> it. >> >> Check out the servlet api. You may be surprised to find a lot of >> methods like this that make dealing with webapps quite easy. >> >> Jake >> >> At 01:42 PM 2/3/2003 -0800, you wrote: >> >>> Hello, >>> I have a question about the WAR directory structure. Namely, where >>> is the appropriate place to put configuration files, log files, and >>> other files that need to be read/written-to by my application? >>> Clearly putting them in the webroot isn't right. Can my application >>> access arbitrary files under WEB-INF? How? I know that conf files >>> can be put in the classpath (e.g. WEB-INF/classes), but this seems >>> like the wrong solution for files that will change after deployment. >>> In the past, I've used the technique of creating my own application >>> root, which contained a webroot/ directory in the WAR format, and >>> pointed the servlet container at that. I used servlet parameters in >>> the web.xml file to specify the location of the application root to my >>> servlets, so that they could access my conf/log files. This works >>> fine, but forces me to 'embrace and extend' the orginal WAR concept. >>> Any suggestions? >>> >>> Thanks, >>> >>> Jim Carlson >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> For additional commands, e-mail: [EMAIL PROTECTED] >> >> JC> --------------------------------------------------------------------- JC> To unsubscribe, e-mail: [EMAIL PROTECTED] JC> For additional commands, e-mail: [EMAIL PROTECTED] -- Best regards, Jacob mailto:[EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]