0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Kotlin/Java on IntelliJ で log を Click したらすぐ該当箇所に飛ぶための魔法

Last updated at Posted at 2025-04-19

結論:logback(-test).xml<pattern> 末尾に at %white(%C.%M\(%F:%L\) と入れる。


  • at IntelliJ にこの文章が stack trace の一部だと認識させ、FQCN 部分を認識して貰う。
  • %C: Fully qualified class name
  • %M: Method name
  • %F:%L: FileName : 行番号
  • %white : 付加情報を良い感じに一段穏やかにする(white と書いてあるが darkmode / lightmode 両方で良い感じに

ezgif-178a92cfb3dd91.png

最小構成で以下。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!-- @formatter:off -->
            <pattern><![CDATA[%d{HH:mm:ss.SSS} [%thread] %highlight(%-5level){TRACE=blue,DEBUG=blue,INFO=green,WARN=yellow,ERROR=red} %cyan(%logger{36}) - %msg at %white(%C.%M\(%F:%L\)) %n]]></pattern>
            <!-- @formatter:on -->
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <!-- ルートロガー設定 -->
    <root level="DEBUG">
        <appender-ref ref="CONSOLE"/>
    </root>
</configuration>

ちなみに %C 部分が無くても () でファイル名と行番号を囲えば Clickable になることもあるが、その場合同名ファイルがあった場合ユーザー選択が必要になってしまう。

image.png

直前に FQCN を書いておけばよしなに扱ってくれる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?