Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1667
| From | markspace <-@.> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Terse code sought |
| Date | 2012-03-25 18:23 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <jkoge2$3ch$1@dont-email.me> (permalink) |
| References | <8f7sm7hd60f72vlc47ul8793gvgv9j1a89@4ax.com> <EXrbr.7472$Ce4.1357@newsfe21.iad> <KYwbr.11514$532.1969@newsfe14.iad> |
>> On 12-03-24 04:32 PM, Roedy Green wrote:
>>> Consider the following code, typical of the sort of thing I pepper my
>>> code with when debugging.
>>>
>>> out.println( "maxBraceNesting:" + maxBraceNesting + "
>>> maxBracketNesting:" + maxBracketNesting + " maxParenthesisNesting:" +
>>> maxParenthesisNesting );
> On 3/24/12 3:32 PM, Arved Sandstrom wrote:
>> System.out.println("${var} = " + ${var});
On 3/24/2012 9:14 PM, Daniel Pitts wrote:
> I'll point out that IntelliJ has a template for this by default. "soutv"
I just want to point out these each of these is somewhat of a rube
solution. A better approach is to use the logger method with parameters:
<http://docs.oracle.com/javase/7/docs/api/java/util/logging/Logger.html#log%28java.util.logging.Level,%20java.lang.String,%20java.lang.Object[]%29>
All of the other ideas mentioned above call the toString() method of
every object concerned, and also use a StringBuilder to construct a new
string. Both of these can have considerable overhead.
Whereas the log method with parameters doesn't invoke any of these if
the log level test does not pass, thus being much "lighter weight" at
run time.
The parameter substitution is "{n}" where n is a number encoded as a
string >= 0. Example:
logger.log( Level.FINEST, "myVar = {0}, otherVar = {1}", myVar,
otherVar );
Read the bit here (at the TOP of the page) where it talks about "msg
argument".
<http://docs.oracle.com/javase/7/docs/api/index.html?java/util/logging/Logger.html>
Back on topic: no I don't know of a macro that auto generates those for
you. :)
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Terse code sought Roedy Green <see_website@mindprod.com.invalid> - 2012-03-24 12:32 -0700
Re: Terse code sought Lew <noone@lewscanon.com> - 2012-03-24 14:50 -0700
Re: Terse code sought Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-24 19:32 -0300
Re: Terse code sought Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-24 21:14 -0700
Re: Terse code sought markspace <-@.> - 2012-03-25 18:23 -0700
Re: Terse code sought Roedy Green <see_website@mindprod.com.invalid> - 2012-03-25 20:28 -0700
Re: Terse code sought markspace <-@.> - 2012-03-26 07:59 -0700
Re: Terse code sought Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-26 07:04 -0300
Re: Terse code sought markspace <-@.> - 2012-03-26 08:02 -0700
Re: Terse code sought Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-26 09:57 -0700
Re: Terse code sought Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-26 20:32 -0300
csiph-web