This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes log4j in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j in jsp" Watch "log4j in jsp" New topic
Author

log4j in jsp

Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi everybody,
Windows 2000 JRun4 log4J1.2.6 JDK1.4.1

I am having trouble identifying Logger in jsp:
<%@ page import="org.apache.log4j.Logger" %>
...
Logger log4 = null;

log4 = Logger.getLogger(this.getClass());
log4.debug("testing log4j");
I tried the above code, and nothing comes out. In case of JSP, I believe the name of the class that would be generated depends on a kind of application server. In that case, getLogger(MyClass.class); is not a good way to define Logger.
But how do I find the name of the class at runtime? It seems that everyone is having no problem using Log4J except me.
Thank you

Shin Hashitani


/*<br /> * Quants Inc.<br /> * Engineer<br /> *<br /> * Shin Hashitani<br /> * hashitani@quants.co.jp<br /> * <a href="http://www.quants.co.jp" target="_blank" rel="nofollow">www.quants.co.jp</a><br />*/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

In the case of a JSP I don't create a logger using the class name at all. I bascially obtain the path to the JSP file from the request, replace the /s with ".", remove the .jsp extension and prefix the logger name with "jsp.". Makes for a nicer logger name that distinguishes JSP loggers from Java class loggers.
So an example logger name (for a page at web/pages/somefolder/mypage.jsp) might be:

Additionally, I created a set of custom tags to do JSP logging so that I don't have to code Java scriplets in the pages just to use logging.
hth,
bear
[ April 14, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: log4j in jsp
 
Similar Threads
Showing message only on console, not to be written in log file
EJB, log4j, and access denied to log4.properties
log4j category
Why do we need mulitple loggers? - Log4j
log4j: Log file not being generated