This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using logging in beans

 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use context sensitive logging in Tomcat 5.5. I've added the following to %catalina_home%/conf/context.xml:



When I do getServletContext().log( "TestMessage");, the message gets logged in localhost and not localhost_jmsorg. What am I doing wrong?

Also, I can get logging to work as above in servlets, but how do I get it to work in Beans where I can't use getServletContext?

TIA,
[ August 12, 2005: Message edited by: Tom Blough ]
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I can get logging to work as above in servlets, but how do I get it to work in Beans where I can't use getServletContext?

You could implement a ServletContext listener that stores the ServletContext in a singleton, and have the beans retrieve it from there. Better yet, have the singleton implement any logging methods you need, passing the arguments through to the ServletContext. I'm not sure what bad side effects this approach might have though.

Or you could just use Log4Java.

-Yuriy
[ August 12, 2005: Message edited by: Yuriy Zilbergleyt ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd also recommend using either the java.util.logging package or Log4J, the latter being the more powerful mechanism.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
latter being the more powerful mechanism.


As well as being simpler to implement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic