Skip to content

Instantly share code, notes, and snippets.

@HaVonTe1
Created October 14, 2015 10:44
Show Gist options
  • Save HaVonTe1/668fd7493d384e436d73 to your computer and use it in GitHub Desktop.
Save HaVonTe1/668fd7493d384e436d73 to your computer and use it in GitHub Desktop.
logback - print filename and line number
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>myapp.log</file>
<encoder><pattern>%logger{35} - [%F:%L] - %msg%n</pattern></encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
<!-- add the following line -->
<includeCallerData>true</includeCallerData>
</appender>
<root level="DEBUG"><appender-ref ref="ASYNC" /></root>
</configuration>
@abtOliver
Copy link

abtOliver commented Apr 24, 2024

If you use

<pattern>%logger{35} - (%F:%L\) - %msg%n</pattern>

for example in logback-test.xml, it is possible to click on the Filename/Linenumber entry on a unit test output,
to get directly to the location of the source code in IDEs like Intellij.

Example output:

LoggerName - (Main.java:14) - Message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment