aspose file tools*
The moose likes Servlets and the fly likes Using logging in beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using logging in beans" Watch "Using logging in beans" New topic
Author

Using logging in beans

Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
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 ]

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
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

Joined: Jan 10, 2002
Posts: 61764
    
  67

I'd also recommend using either the java.util.logging package or Log4J, the latter being the more powerful mechanism.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bear Bibeault:
latter being the more powerful mechanism.


As well as being simpler to implement.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
 
subject: Using logging in beans