我正在使用logback AsyncAppender ch.qos.logback.core.rolling.RollingFileAppender将日志打印到具有以下配置的文件。如果在控制台上打印但在日志文件方法名称和行号中打印为"?"则一切正常。字符。
Logback配置
<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>
示例输出
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
必需的输出
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
答案 0 :(得分:1)
我遇到了同样的问题并尝试了两种方法来修复它。它们如下所示,但只是第二种方式:
1: <includeCallerData>true</includeCallerData>
有些人说解决这个问题很好,但不适合我。
2: <param name="locationInfo" value="true" />
添加此行后,我设法让asyncappender输出行号。
享受第二种方式!