Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print Class Name, Method name and line number using Logger's info()

I already configured logback file to get classname, method name and line number.

 <pattern> %d{HH:mm:ss.SSS} [%thread] %-5level %class{36}.%M %L - %msg%n </pattern>

I want to print log message when entering and existing method. How can i do that within the class using info() method. I used the code below. But it didnt print what i wanted.

I use org.slf4j.Logger and Logback logging

LOG.info("Entering " + );

This is what I got :

14:41:48.097 [main] INFO  c.a.j.orgchart.CsvPersonReader - Entering 

I want to print something like this:

14:41:48.097 [main] INFO  c.a.j.orgchart.CsvPersonReader.[MethodName] [Linenumber] - Entering 
like image 971
amal Avatar asked Jun 01 '15 18:06

amal


1 Answers

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
     <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level  %class{36}.%M %L  - %msg%n</pattern>
     </encoder>
</appender>
like image 88
amal Avatar answered Nov 12 '22 06:11

amal