Can I have interactive class names in a console release in IntelliJ?

When starting the server inside IntelliJ, you can see the console output in the window at the bottom of the screen.

Is there a way to format the output so that IntelliJ recognizes class names and makes them clickable? Then, when I see the class name on the server output, I could click on it and go straight there.

Thanks:)

+15
intellij-idea
source share
7 answers

There is. Taken from online help http://www.jetbrains.com/idea/webhelp/setting-log-options.html

If you use third-party logging tools, you can do a message output that mimics the standard binding to the source code as for the stacktrace (at. (:)) line. To do this, you must add a specific conversion template to your log.xml configuration file. For example, in the log4j conversion template, this will be

<param name="ConversionPattern" value="%-5p - [%-80m] - at %c.%M(%F:%L)%n"/> 

However, the output is pretty ugly with full names, method names, etc.

+8
source share

As in IntelliJ 14 and the alternative to digging through the IntelliJ settings, some trial errors and errors showed that there was something with the template

 (anyfile.ext:line) 

which is preceded by at least one . in the console, turns into a file link if there is a file known by that name, for example. .(Whatever.java:55) , in the workspace, excluding libraries.

I am using logback. So, at least in my logback.xml, to get links to my classes, I included messages in my template

 .\(%class{0}.java:%line\) 
  • .\( \) → The dot must precede the file name: line pattern and file name: line pattern enclosed in parentheses. In this case, alphabetic parentheses are required to return to the log.
  • %class{0} → Just class name without package
  • .java → So that it matches the full file name
  • :%line → Is the line of the code log

In fact, I have other things that always include at least one . to the part (filename:line) , so it is also matched by IntelliJ.

 <pattern>%highlight(%-5level) %d{yyyy-MM-dd'T'HH:mm:ss.SSS} %yellow([%thread]) %blue(%logger{36}\(%class{0}.java:%line\)) %msg%n</pattern> 
+25
source share

You can define your own output filters or print file paths with line numbers separated by a colon, or full paths, or paths relative to the project source roots.

A custom output filter can use the following variables: $FILE_PATH$ , $LINE$ .

+2
source share

To do things REALLY, you need to complete the full frame snapshot notation. How it MUST NOT just put an end to "." in front of the brackets. If you have two classes with the same name but with different packages, IntelliJ will choose the first one that it finds. To make this work CORRECTLY even in this case you need to write

fullqualifiedclassname + "." + methodname + "(" + simpleclassname + ".java:" + linenumber + ")"

If you do not know the line number using ": 1", I worked for me

0
source share

To complete @JasonDunkelberger's answer, after errors and trials, I got the best regular exception that Intellij probably parses to find where to place the hyperlinks:

 (at )?+.*\..*\(.*?\) 

In @JasonDunkelberger's answer, in some cases, if there are parentheses or two “at” letters after the link, the link is not activated.

0
source share

after some testing, I got a workable setup in a spring boot project with Intelligent IDEA ULIMATE 2017.3.2 and logback 1.2.3
The settings in logback-spring.xml are something like this:

 <configuration> <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(at %class.%method){cyan} \\(%file:%line\\) %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> <include resource="org/springframework/boot/logging/logback/base.xml"/> </configuration> 

% clr (in% class.% method) {cyan} \ (% file:% line \)
this decision

0
source share

Install the awesome IntelliJ Plugin console from the Marketplace: https://plugins.jetbrains.com/plugin/7677-awesome-console

Then everything in your terminal, including maven build failures for Java classes, will also be active.

0
source share

All Articles