• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Writing a log file for my servlet

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to write a log file for my servlet. I am using a FileWriter now and it is working fine. The problem is the file path.

now i am using absolute path , the exact hardcoded location of the file. but i donot want to do this.

I want to give a relative location to the file path, that is, inside the server/webapps folder. so that even if my server location changes i need not change the log file path.
how can i get this?

regards,
Surendar
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I use log4j which allows you to configure all of this stuff from a properties file.


As to your question:
One thing to keep in mind is that a Java webapp doesn't necessarily reside in a directory. They can also be deployed and run from a packed war archive.
The war file doesn't even need to be on the same machine.

The ServletContext.getRealPath method will find the file system path to any resource in your webapp. Using getRealPath("/") will find the root of your webapp. If, as mentioned earlier, your app hasn't been deployed as an exploded file system, get real path will return null.
For this reason, relying on getRealPath makes your webapp less portable.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic