Created
October 14, 2015 10:44
-
-
Save HaVonTe1/668fd7493d384e436d73 to your computer and use it in GitHub Desktop.
logback - print filename and line number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
good one for sure, but this process of printing line number and file name is slow , therefor if any one has concern about speed. they may avoid this . reference http://logback.qos.ch/manual/layouts.html
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
nice