Formatting of captured output (jump to line message)


Anybody know if its possible to dump the filename and line number (from an
StackTraceElements) out to system.err and have IDEA highlight the location
as a jump-to link? like its does with a full exception stacktrace.. is it
just a formatting trick?

Its just that I've created a resourcebundle that'll throw warnings when it
comes accross missing keys e.g. "Missing key: mylabel at (xyz.java:123)"
rather than stop the program (while Im developing). It'd be handy to jump
to the offening keys as sometimes its just a typo.

I could force a stackdump, but its kinda ugly.

- Richard


5 comments
Comment actions Permalink

Thread.dumpStack() ?

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

Anybody know if its possible to dump the filename and line number
(from an StackTraceElements) out to system.err and have IDEA highlight
the location as a jump-to link? like its does with a full exception
stacktrace.. is it just a formatting trick?

Its just that I've created a resourcebundle that'll throw warnings
when it comes accross missing keys e.g. "Missing key: mylabel at
(xyz.java:123)" rather than stop the program (while Im developing).
It'd be handy to jump to the offening keys as sometimes its just a
typo.

I could force a stackdump, but its kinda ugly.

- Richard




0
Comment actions Permalink

Hello Maxim,

Thread.dumpStack() ?


Hmmm, not really - I mean I'm dumping these messages out as warnings via
java.logging and didnt want the contents of several stackdump to pick through
in the logs. I'd like to see just a sequence of resource wanings e.g.

WARNING: Missing Resource Exception: title (SelectLocaleDialog.java:78)
WARNING: Missing Resource Exception: sizeLabel (SelectLocaleDialog.java:83)
WARNING: Missing Resource Exception: sampleLabel (SelectLocaleDialog.java:86)
WARNING: Missing Resource Exception: fontSamplePanel (SelectLocaleDialog.java:87)
WARNING: Missing Resource Exception: fontLabel (SelectLocaleDialog.java:90)

Just wondered wether there was some markup trick I could use to fool idea
into creating a jump-to href like link?

- Richard


0
Comment actions Permalink

Well, I see. Try following:
at .foo(:]]>)

for example:
at com.intellij.psi.impl.source.tree.ElementTypeManager.foo(ElementTypeManager.java:10)

line must start with 'at'. 'foo' may be just 'foo' or any other identifier.

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

Hello Maxim,

>> Thread.dumpStack() ?
>>

Hmmm, not really - I mean I'm dumping these messages out as warnings
via java.logging and didnt want the contents of several stackdump to
pick through in the logs. I'd like to see just a sequence of resource
wanings e.g.

WARNING: Missing Resource Exception: title
(SelectLocaleDialog.java:78)
WARNING: Missing Resource Exception: sizeLabel
(SelectLocaleDialog.java:83)
WARNING: Missing Resource Exception: sampleLabel
(SelectLocaleDialog.java:86)
WARNING: Missing Resource Exception: fontSamplePanel
(SelectLocaleDialog.java:87)
WARNING: Missing Resource Exception: fontLabel
(SelectLocaleDialog.java:90)
Just wondered wether there was some markup trick I could use to fool
idea into creating a jump-to href like link?

- Richard




0
Comment actions Permalink

Hello Maxim,

Well, I see. Try following:
at <fully quialifed class name>.foo(<filename.java>:<line_number>)
for example:
at
com.intellij.psi.impl.source.tree.ElementTypeManager.foo(ElementTypeMa
nager.java:10)
line must start with 'at'. 'foo' may be just 'foo' or any other
identifier.


Thanks Maxim, that worked a treat! Thought they're must be some syntax magic
going on.

StackTraceElement[] ste = new Exception().getStackTrace(); for (int i = 0; i < ste.length; i++) { StackTraceElement stackTraceElement = ste+; if (!stackTraceElement.getClassName().equals(this.getClass().getName()) && !stackTraceElement.getClassName().equals("java.util.ResourceBundle")) { logger.log(Level.WARNING, "Missing Locale Resource: " + key + "\nat " + ste+.getClassName() + "." + ste+.getMethodName() + "(" + ste+.getFileName() + ":" + ste+.getLineNumber() + ")"); break; } } ]]>

- Richard



0
Comment actions Permalink

Hello Richard,

If the logger below is a log4j logger then you can use the following pattern
%d %5p - <%m> - at %c.%M(%F:%L)%n (http://www.intellij.org/twiki/bin/view/Main/IdeaTips)
to automatically get the appropriate filename and line number information
which then helps IDEA to hyperlink.

HTH.
Thanks,
--Venkat.

Hello Maxim,

>> Well, I see. Try following:
>> at .foo(:) >> for example: >> at >> com.intellij.psi.impl.source.tree.ElementTypeManager.foo(ElementTypeM >> a >> nager.java:10) >> line must start with 'at'. 'foo' may be just 'foo' or any other >>]]> identifier.

Thanks Maxim, that worked a treat! Thought they're must be some syntax
magic going on.

<code>
StackTraceElement[] ste = new Exception().getStackTrace();
for (int i = 0; i < ste.length; i++) {
StackTraceElement stackTraceElement = ste+;
if
(!stackTraceElement.getClassName().equals(this.getClass().getName())
&&
!stackTraceElement.getClassName().equals("java.util.ResourceBundle"))
{
logger.log(Level.WARNING, "Missing Locale Resource: " + key
+ "\nat " + ste+.getClassName() + "." + ste+.getMethodName()
+ "(" + ste+.getFileName() + ":" + ste+.getLineNumber() +
")");
break;
}
}
</code>

- Richard




0

Please sign in to leave a comment.