Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tomcat logger

 
manoj r patil
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext.log()
and you can get the servlet context from the session.
 
Beth Barja
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It really is very simple:
ServletContext context = session.getServletContext();
context.log("this gets logged to localhost_log.YYYYMMDD");
:roll:
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic