You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Josh <jr...@yahoo.com> on 2001/02/26 14:29:30 UTC

servlet.log question

In the Struts example code wherever debug/log information is being printed to
the log, the code appears:

if (servlet.getDebug() >= 1)
    servlet.log("debug/log message");

I was wondering if that was advantageous over:

servlet.log("debug/log message", 1);

I am under the impression that the two samples work the same, and would prefer
to use the second, however I was wondering if there was some sort of
performance issue, etc . . . 

Thanks,
Josh


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

Re: servlet.log question

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Josh wrote:

> In the Struts example code wherever debug/log information is being printed to
> the log, the code appears:
>
> if (servlet.getDebug() >= 1)
>     servlet.log("debug/log message");
>

This is also my typical pattern throughout the Struts code itself.

>
> I was wondering if that was advantageous over:
>
> servlet.log("debug/log message", 1);
>
> I am under the impression that the two samples work the same, and would prefer
> to use the second, however I was wondering if there was some sort of
> performance issue, etc . . .
>

If you do this as a method call, any expression required to calculate
the
debugging message will be performed, whether or not you ever really
write the log
message out.  This can be pretty expensive if you are doing something
like this:

    servlet.log("Name=" + name + " and value=" + value, 1);

which does a bunch of string concatenations.  You don't mind paying the
price if
you are really doing the debugging output (because it's just for testing
anyway),
but you really do *not* want to spend the time doing the string
concatenations in
production.  Using the "if" approach avoids that.

>
> Thanks,
> Josh
>

Craig McClanahan

Re: servlet.log question

Posted by Alan Yackel <ay...@home.com>.
The first one should be faster because in the second one there is a String object

created.  What be faster yet is if you could do something like this:

if(servlet.debug >= 1)
    servlet.log("debug/log message");

Then you wouldn't have that method call slowing you down.

Alan Yackel

Josh wrote:

> In the Struts example code wherever debug/log information is being printed to
> the log, the code appears:
>
> if (servlet.getDebug() >= 1)
>     servlet.log("debug/log message");
>
> I was wondering if that was advantageous over:
>
> servlet.log("debug/log message", 1);
>
> I am under the impression that the two samples work the same, and would prefer
> to use the second, however I was wondering if there was some sort of
> performance issue, etc . . .
>
> Thanks,
> Josh
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/