Idea Console Output

摘要

IDEA Console日志输出点击直接跳转到源代码

在使用第三方日志记录工具,想要消息的输出模仿标准的链接到源代码的堆栈跟踪行

<fully-qualified-class-name>.<method-name>(<file-name>:<line-number>)

可通过添加特定的转换模式,按照:类名.方法名(文件名:行号) 的格式输出。

If you are using third-party logging tools, you might want to make the message's output that mimics a standard linkage to the source code as for stack trace line (at <fully-qualified-class-name>.<method-name>(<file-name>:<line-number>)). For that, add specific Conversion Pattern to your log.xml configuration file.

For example, in a log4j Conversion Pattern this would be <param name="ConversionPattern" value="%-5p - [%-80m] - at %c.%M(%F:%L)%n"/>.

logback

示例1

%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20}.%method\\(%file:%line\\) - %msg%n

示例2

%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %yellow(at %class.%method) \\(%file:%line\\) %n%clr(>>>>>>) %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}

log4j2

示例1

%style{%d{yyyy-MM-dd HH:mm:ss.SSS}}{dim} %highlight{%level{length=4}}{STYLE=Logback} %cyan{%c{1}.%M(%F:%L)} %style{:}{dim} %msg%n%throwable

示例2

%style{%d{yyyy-MM-dd HH:mm:ss.SSS}}{dim} %highlight{%-5level} %magenta{%pid} %style{--- [%t]}{dim} %cyan{%c{1.}.%M(%F:%L)} %style{:}{dim} %msg%n%throwable

参考资源

  • https://www.jetbrains.com/help/idea/2020.1/setting-log-options.html
  • https://www.jetbrains.com/help/idea/2020.2/setting-log-options.html
  • https://stackoverflow.com/questions/7930844/is-it-possible-to-have-clickable-class-names-in-console-output-in-intellij