我从logback中得到了一些奇怪的行为,问题是log.debug()调用停止工作而不是写入控制台。
以下是我创建Logger和调用日志函数的方法:
public class MyApp extends Application {
private static Logger log = LoggerFactory.getLogger(MyApp.class);
@Override
public void onCreate() {
log.info("log.isDebugEnabled() {}", log.isDebugEnabled());
log.error("error test");
log.debug("HELLO {}", "WORLD");
log.debug("debug test");
..............
/*some code here*/
..............
super.onCreate();
}
..............
}
如您所见,没有调试行,只有错误和信息。
这是我的logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="EXT_FILES_DIR" value="/mnt/sdcard/Android/data/my_dir/files/logs" />
<timestamp key="bySecond" datePattern="dd.MM.yy'__'HH.mm.ss"/>
<appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
<encoder>
<pattern>%d{HH:mm:ss} :: %-5level :: THREAD [%thread] IN CLASS %logger{5} ON LINE %line - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${EXT_FILES_DIR}/my_log-${bySecond}.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} :: %-5level :: THREAD [%thread] IN CLASS %logger{5} ON LINE %line - %msg%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>${EXT_FILES_DIR}/my_log-${bySecond}.%i.log.txt</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>10</MaxIndex>
</rollingPolicy>
<triggeringPolicy
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>2MB</MaxFileSize>
</triggeringPolicy>
</appender>
<root level="DEBUG">
<appender-ref ref="logcat" />
<appender-ref ref="FILE"/>
</root>
</configuration>
有什么建议吗?问候。
答案 0 :(得分:4)
问题出在我的设备Hyawei Honor 4x中 - 制造商禁用了调试级别的日志。解决方案是:
拨打
*#*#2846579#*#*
点击ProjectMenu