前言
Android机器在打印logcat时,偶然由于日志输出过大,会出现如下问题
adb logcat read: unexpected EOF!
然后被强制性退出了打印。
解决的方法有两种,一种是使用adb临时修改,断电就恢复,一种是代码中修改,永久性存在。
正文
永久修改logcat缓存
kernel\drivers\staging\android\logger.c
static int __init logger_init(void) { int ret; ret = create_log(LOGGER_LOG_MAIN, 256*1024*8); if (unlikely(ret)) goto out; ret = create_log(LOGGER_LOG_EVENTS, 256*1024*8); if (unlikely(ret)) goto out; ret = create_log(LOGGER_LOG_RADIO, 256*1024*8); if (unlikely(ret)) goto out; ret = create_log(LOGGER_LOG_SYSTEM, 256*1024*8); if (unlikely(ret)) goto out; out: return ret; }
如果需要修改缓存大小,修改create_log的第二个参数即可, 之前为256,本人将其乘以了8
临时修改logcat -G 缓存
可以使用logcat -G + 值m 修改缓存大小。
# 修改缓存为100m adb logcat -G 100m
修改日志打印
adb logcat -g # 下面是打印日志 main: ring buffer is 10Mb (2Mb consumed), max entry is 5120b, max payload is 4068b system: ring buffer is 10Mb (299Kb consumed), max entry is 5120b, max payload is 4068b crash: ring buffer is 10Mb (0b consumed), max entry is 5120b, max payload is 4068b # 使用logcat -G 修改缓存大小 adb logcat -G 100m # 修改后的打印日志 adb logcat -g main: ring buffer is 100Mb (2Mb consumed), max entry is 5120b, max payload is 4068b system: ring buffer is 100Mb (300Kb consumed), max entry is 5120b, max payload is 4068b crash: ring buffer is 100Mb (0b consumed), max entry is 5120b, max payload is 4068b # 设置最大值为257m就会出现异常提示 adb logcat -G 257m failed to set the 'main' log size
参考文章
© 版权声明