Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.help Subject: Re: Terse code sought Date: Sun, 25 Mar 2012 18:23:13 -0700 Organization: A noiseless patient Spider Lines: 44 Message-ID: References: <8f7sm7hd60f72vlc47ul8793gvgv9j1a89@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 26 Mar 2012 01:23:15 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="QNqT5u6Ryx/DB+LpnoCWdQ"; logging-data="3473"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tPMcK5KChg/+qEVg5Qfyw5E1MTSOCXdo=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120312 Thunderbird/11.0 In-Reply-To: Cancel-Lock: sha1:CiU+WSgMaiehHJwtIw4hE1bNfe4= Xref: csiph.com comp.lang.java.help:1667 >> 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: 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". Back on topic: no I don't know of a macro that auto generates those for you. :)