File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes tomcat logger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat logger" Watch "tomcat logger" New topic

tomcat logger

manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
I want to throw errors/exceptions to server's log file from jsp as well as java class files. How can I achieve it?
Thanks & Regards,

love your job and not your company;
...because you never know when your company will stop loving you!
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 567
and you can get the servlet context from the session.

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Beth Barja

Joined: Nov 02, 2001
Posts: 10
I need to do this also.
Could you show a code example of how to do this? How to instantiate the object, etc...
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 567
It really is very simple:
ServletContext context = session.getServletContext();
context.log("this gets logged to localhost_log.YYYYMMDD");
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Why not to use the implicit object available in your jsp: application itself which is the ServletContext? :roll:
application.log("this gets logged to localhost_log.YYYYMMDD");
Which saves your one line of typing at least.
[ June 16, 2002: Message edited by: Roseanne Zhang ]
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 567
I agree. Here's the link:
subject: tomcat logger
It's not a secret anymore!