This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

log4j: right path for the log file

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have the following problem. I am using log4j for logging my servlets but I don't understand how configure log4j in order to write the log file in the WEB-INF directory. I don't want to use an absolute path, in order to work on localhost and on the server without change the configuration. Is there a way?
 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to write there? I consider WEB-INF to be read only.
Better to write logs to /var/log or /tmp or /log
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Pat said its not a good practice but still have to do then.
1)Use servlet method getRealPath (deprecated) and set the same into system property as LOG_LOCATION.
2)you can read system prperties into log4j.properties as ${LOG_LOCATION}/app.log
3) if some thing goes wrong the google out.

Thanks,
Sachin
 
Marshal
Posts: 67293
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sachin Kr", please check your private messages for an important administrative matter.
 
Max Qua
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys.
Yes, WEB-INF maybe is not the best place for the log. I would like to have the log in a directory of my web application space.
But why should I use a deprecated method? Is there another way?
Thanks
 
Bear Bibeault
Marshal
Posts: 67293
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd rethink that. Placing dynamic files inside your web app alters its structure and can make it harder to redeploy as the app no longer matches its war file.

That said, the ServletContext.getRealPath method is not deprecated. This is something you could have determined by simply looking at the JavaDoc for the Servlet API.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing to consider, whether you use an absolute path or if you use getRealPath is that writing anything inside your webapp's file structure will make your application non-portable and may limit how it can be deployed.

JEE web applications can, but aren't required to, be deployed from an operating system's file structure. Containers can also deploy a war file without unpacking it. Some do this by default. There may be others than only deploy application's this way. If the application is not deployed from the file system, getRealPath will return null. This makes sense because there won't be a path to the resource.

If you write your application so that it is required to be deployed in a particular way, you have made it non-portable and have limited what environments on which it can be run.



Maybe the right question is:
Why do you want to write the log files to your application's file structure?
Is it just so that you can read the logs online?
If so, you might consider writing a servlet that can read the file and stream it to the browser.

Don't forget to consider the security implications of making log files open to the web.
[ November 27, 2008: Message edited by: Ben Souther ]
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!