Replace System.out with LOG.debug()

Wasn't there an intention to replace System.out with LOG.debug() (with if
(LOG.isDebugEnabled())?
I remember seeing (or was I dreaming) it but can not find it any more


10 comments

Hello Alex,

AR> Wasn't there an intention to replace System.out with LOG.debug()
AR> (with if
AR> (LOG.isDebugEnabled())?
AR> I remember seeing (or was I dreaming) it but can not find it any
AR> more

As far as I know, the IG inspection which searches for uses of System.out
does not provide a quickfix. In Demetra, you can set up a Structural Search
inspection to perform the searcn and replace for you.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Alex Roytman wrote:

Wasn't there an intention to replace System.out with LOG.debug() (with if
(LOG.isDebugEnabled())?
I remember seeing (or was I dreaming) it but can not find it any more


Hi Alex,

Why don't you use the power of live templates? Here's what I am using
whenever I need to insert debug code:


if($VAR$.isDebugEnabled()) {
$VAR$.debug("$END$");
}

For the above code I am using the abbreviation "debug". Anywhere in my
Java code I can write "debug", hit the TAB key, and you're in business ;)

Hope it makes sense, cheers!
-florin

0

You can do structural replace finding
System.out.println($a$);
and replacing it by
if (LOG.isDebugEnabled()) {
LOG.debug($a$);
}

Alex Roytman wrote:

Wasn't there an intention to replace System.out with LOG.debug() (with if
(LOG.isDebugEnabled())?
I remember seeing (or was I dreaming) it but can not find it any more



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Dmitry Jemerov (JetBrains) wrote:

In Demetra, you can set up a
Structural Search inspection to perform the searcn and replace for you.


Unfortunately, this is not an optimal solution because SS is not powerful enough
to distinguish whether a statement is wrapped in an if-clause or not - at least
AFAIK.

Sascha

0

Sascha Weinreuter wrote:

Dmitry Jemerov (JetBrains) wrote:

>> In Demetra, you can set up a
>> Structural Search inspection to perform the searcn and replace for you.


Unfortunately, this is not an optimal solution because SS is not powerful enough
to distinguish whether a statement is wrapped in an if-clause or not - at least
AFAIK.


I'm stupid - I should have read the whole thread ;)

I thought this was about finding LOG.debug() that isn't wrapped into if
(LOG.isDebugEnabled()) { ... }

Sascha

0

Sascha Weinreuter wrote:

Unfortunately, this is not an optimal solution because SS is not powerful enough
to distinguish whether a statement is wrapped in an if-clause or not


It will be.

--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Hi,

The problem wit SS is that you can only replace System.out with lets say
debug. If it is an intention you can choose to make it debug or info or
warning or remove etc

Thank you

Alex

"Maxim Mossienko (JetBrains)" <Maxim.Mossienko@jetbrains.com> wrote in
message news:dscu24$m46$1@is.intellij.net...

You can do structural replace finding
System.out.println($a$);
and replacing it by
if (LOG.isDebugEnabled()) {
LOG.debug($a$);
}

>

Alex Roytman wrote:

>> Wasn't there an intention to replace System.out with LOG.debug() (with if
>> (LOG.isDebugEnabled())?
>> I remember seeing (or was I dreaming) it but can not find it any more
>>
>>
>
>

--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"



0

Of course I use live templates. But here I am talking refactoring some rity
code without having to do 100 cut and pastes


"Florin PATRASCU" <fpatrascu@masterfile.com> wrote in message
news:dsctjo$kok$1@is.intellij.net...

Alex Roytman wrote:

>> Wasn't there an intention to replace System.out with LOG.debug() (with if
>> (LOG.isDebugEnabled())?
>> I remember seeing (or was I dreaming) it but can not find it any more
>>
>>
>

Hi Alex,

>

Why don't you use the power of live templates? Here's what I am using
whenever I need to insert debug code:

>
>

if($VAR$.isDebugEnabled()) {
$VAR$.debug("$END$");
}

>

For the above code I am using the abbreviation "debug". Anywhere in my
Java code I can write "debug", hit the TAB key, and you're in business ;)

>

Hope it makes sense, cheers!
-florin



0

BTW, what LOG you are using? We also use a LOG constant per class, but
ours is a project class and maybe have different method calls.

What about defining some structural replace pairs and be able to show them
as intentions if the search term matches?

Tom

0

Please sign in to leave a comment.