1

I am using logback AsyncAppender ch.qos.logback.core.rolling.RollingFileAppender to print logs to file with following configuration. Everything is working fine if printing on console but in log file method name and line number are printing as "?" character.

Logback Configuration

<appender name="activity_appender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${log.folder}/${log.activity.fileName}</File>
        <encoder>
            <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} -APP- %X{HOST} %X{requestId} [%t] %.-5level %logger{60}.%M-%L - %msg %n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>${log.folder}/${log.activity.fileName}-%d{YYYY-MM-dd}.%i
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 100MB -->
                <maxFileSize>${log.file.maxsize}</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>

Sample Output

2015-08-11 16:30:00.051 -APP-   [scheduler-1] WARN c.some.package.class.?-? - Configuration not present for configType:global or keysms.template Picking default value: 2 

Required Output

2015-08-11 16:30:00.051 -APP-   [scheduler-1] WARN c.some.package.class.method-98 - Configuration not present for configType:global or keysms.template Picking default value: 2 
Himanshu Goel
  • 574
  • 1
  • 8
  • 26
  • possible duplicate http://stackoverflow.com/questions/13944641/logback-ayncappender-not-printing-file-and-line-number – user1516873 Aug 11 '15 at 11:34

1 Answers1

3

I run into the same problem and tried two ways to fix it. they are shown below, but just the second way worked:

1: <includeCallerData>true</includeCallerData>

some said it's good to solve the issue, but not for me.

2: <param name="locationInfo" value="true" />

after adding this line, i managed to make asyncappender output the line number.

enjoy the second way!

Sheldon Wei
  • 1,198
  • 16
  • 31