You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Joel Rees <jo...@alpsgiken.gr.jp> on 2002/02/21 07:11:14 UTC

logging from jsp

My initial experiments with 1.1.3 gives me compiler errors when I tried to
instantiate a category directly in jsp pages. For instance,

<%@ page import="org.apache.log4j.Category" %>
<html>
<% static Category slog = Category.getInstance( class.getName() ); %>
...

gives me

org.apache.jasper.JasperException: Unable to compile class for
JSPD:\jakarta\tomcat-3.2.4\work\localhost_8080%2FNakaiSample\_0002fHXJTestMe
nu_0002ejspHXJTestMenu_jsp_11.java:64: '}' no statement
                out.write("\r\n\r\n");

                                            ^

etc. in the browser. I note that not referencing a class name in the
instantiation would probably cause me problems, but I haven't yet figured
out where to look up the class name that jsp pages operate under.

I have been able to build a little class that the jsp page imports, and log
through that class (but have not been able to configure the class). I had to
use static initialization in that class.

Is it possible to directly instantiate a category or logger  in a jsp page?
If so, could someone show me where to look in the docs? (I looked but I
probbaly missed a lot.)

Joel Rees



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging from jsp, converting from category to logger and getting NoSuchField

Posted by Joel Rees <jo...@alpsgiken.gr.jp>.
Thanks for some clues. At least I can think the things I have been trying
should have worked.

Maybe. I forgot to say I am running Tomcat 3.2 with my log4j 1.2 beta. Java
is 1.3. The web-app is configured outside the tomcat directory tree. Had
similar problems with 3.3. Boss says this project will be in 3.2.

Combining my results into one, to save list wear, and because I am beginning
to wonder if it isn't the same problem, that I've fumbled my setup somehow:

----- Original Message -----

Mark Derricutt wrote (about jsp):
> I handled this a slighly different way, and just added a log4j JSP tag
that
> took a level, message, and category attributes:
>
>   <jtime:log4j category="main" level="debug" message="w00p" />

Looks like a good place to start when I can get to tags. I can't even read
it yet. But it should help me get a target to aim at.

----- Original Message -----

Kevin Steppe wrote (about jsp):
> I would recommend:
> <% Category slog = Category.getInstance(this.class.getName()); %>

I've done something like this, but here's what happened when I tried again:
 Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile class for
JSPD:\jakarta\tomcat-3.2.4\work\localhost_8080%2FNakaiSample\_0002fHXJTestMe
nu_0002ejspHXJTestMenu_jsp_2.java:67: ????????
                 Category blog = Category.getInstance(this.class.getName());
                                                      ^
(pointing to the "this.class.getName()")
(The Japanese error message says "Invalid Format" or "Invalid Form".)

> The important part is that _this_ is referencable in a JSP (it's just a
Servlet
> class anyway).

Okay, so it should be accessible like a servlet. That should help.

----- Original Message -----

Scott Farquhar wrote (about converting to Logger):
> Why not use this:
>
> import org.apache.log4j.Logger;
> import org.apache.log4j.BasicConfigurator;
>
> public class HXDbg
> {
>  public static Logger glog = Logger.getLogger( HXDbg.class.getName() );;
>  static
>  {
>   BasicConfigurator.configure();
>  }
> }

I've done something like this, too, and here's what happened when I tried
this one:
Internal Servlet Error:
...
Root cause:
java.lang.NoSuchFieldError: glog
...

----- Original Message -----
Scott Farquhar also wrote (about jsp):
> The problem you get is from using a static category in your jsp in that
> manner.
>
> Either use a non-static logger, or use the jsp taglibs found in the
> jakarta jsp project.

(See above.)

Again, thanks for your help. I'll look some more tomorrow.

Joel



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging from jsp

Posted by Mark Derricutt <ma...@talios.com>.
I handled this a slighly different way, and just added a log4j JSP tag that 
took a level, message, and category attributes:

  <jtime:log4j category="main" level="debug" message="w00p" />

Then the code I get an instance of the category as normal, and theres an if 
block checking the level..  works quite well, but doesn't answer your 
question...

--On Thursday, February 21, 2002 15:11:14 +0900 Joel Rees 
<jo...@alpsgiken.gr.jp> wrote:

> Is it possible to directly instantiate a category or logger  in a jsp
> page? If so, could someone show me where to look in the docs? (I looked
> but I probbaly missed a lot.)



                                    -- \m/ --
  "...if I seem super human I have been misunderstood." (c) Dream Theater
         mark@talios.com - ICQ: 1934853 JID: talios@myjabber.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging from jsp

Posted by Scott Farquhar <sc...@atlassian.com>.
The problem you get is from using a static category in your jsp in that
manner.

Either use a non-static logger, or use the jsp taglibs found in the
jakarta jsp project.

Cheers,
Scott

Joel Rees wrote:

> My initial experiments with 1.1.3 gives me compiler errors when I tried to
> instantiate a category directly in jsp pages. For instance,
> 
> <%@ page import="org.apache.log4j.Category" %>
> <html>
> <% static Category slog = Category.getInstance( class.getName() ); %>
> ...
> 
> gives me
> 
> org.apache.jasper.JasperException: Unable to compile class for
> JSPD:\jakarta\tomcat-3.2.4\work\localhost_8080%2FNakaiSample\_0002fHXJTestMe
> nu_0002ejspHXJTestMenu_jsp_11.java:64: '}' no statement
>                 out.write("\r\n\r\n");
> 
>                                             ^
> 
> etc. in the browser. I note that not referencing a class name in the
> instantiation would probably cause me problems, but I haven't yet figured
> out where to look up the class name that jsp pages operate under.
> 
> I have been able to build a little class that the jsp page imports, and log
> through that class (but have not been able to configure the class). I had to
> use static initialization in that class.
> 
> Is it possible to directly instantiate a category or logger  in a jsp page?
> If so, could someone show me where to look in the docs? (I looked but I
> probbaly missed a lot.)
> 
> Joel Rees
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


-- 
Scott Farquhar :: scott@atlassian.com

Atlassian :: http://www.atlassian.com
     Supporting YOUR J2EE World



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging from jsp

Posted by Kevin Steppe <ks...@pacbell.net>.
I would recommend:
<% Category slog = Category.getInstance(this.class.getName()); %>

The important part is that _this_ is referencable in a JSP (it's just a Servlet
class anyway).
The static declaration is nice but not all that necessary.  There is only one
object for slog anyway, even if you have multiple references -- and multiple
references aren't that much extra memory.

Note the following is based on my Tomcat 4.0.1 experience:
If you look in \tomcat\work\YOURAPP\ you will find all the Servlet java source
being written from the jsp page.  You can then see exactly what is going wrong.

Kevin

Joel Rees wrote:

> My initial experiments with 1.1.3 gives me compiler errors when I tried to
> instantiate a category directly in jsp pages. For instance,
>
> <%@ page import="org.apache.log4j.Category" %>
> <html>
> <% static Category slog = Category.getInstance( class.getName() ); %>
> ...
>
> gives me
>
> org.apache.jasper.JasperException: Unable to compile class for
> JSPD:\jakarta\tomcat-3.2.4\work\localhost_8080%2FNakaiSample\_0002fHXJTestMe
> nu_0002ejspHXJTestMenu_jsp_11.java:64: '}' no statement
>                 out.write("\r\n\r\n");
>
>                                             ^
>
> etc. in the browser. I note that not referencing a class name in the
> instantiation would probably cause me problems, but I haven't yet figured
> out where to look up the class name that jsp pages operate under.
>
> I have been able to build a little class that the jsp page imports, and log
> through that class (but have not been able to configure the class). I had to
> use static initialization in that class.
>
> Is it possible to directly instantiate a category or logger  in a jsp page?
> If so, could someone show me where to look in the docs? (I looked but I
> probbaly missed a lot.)
>
> Joel Rees
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>