Mac*_*rse 106
Logcollector是一个不错的选择,但您需要先安装它.
当我想通过邮件发送日志文件时,我通常会执行以下操作:
adb shell logcat > log.txtuse*_*692 29
我希望这段代码可以帮助别人.我花了两天时间弄清楚如何从设备登录,然后过滤它:
public File extractLogToFileAndWeb(){
//set a file
Date datum = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ITALY);
String fullName = df.format(datum)+"appLog.log";
File file = new File (Environment.getExternalStorageDirectory(), fullName);
//clears a file
if(file.exists()){
file.delete();
}
//write log to file
int pid = android.os.Process.myPid();
try {
String command = String.format("logcat -d -v threadtime *:*");
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder result = new StringBuilder();
String currentLine = null;
while ((currentLine = reader.readLine()) != null) {
if (currentLine != null && currentLine.contains(String.valueOf(pid))) {
result.append(currentLine);
result.append("\n");
}
}
FileWriter out = new FileWriter(file);
out.write(result.toString());
out.close();
//Runtime.getRuntime().exec("logcat -d -v time -f "+file.getAbsolutePath());
} catch (IOException e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
//clear the log
try {
Runtime.getRuntime().exec("logcat -c");
} catch (IOException e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
return file;
}
Run Code Online (Sandbox Code Playgroud)
正如@mehdok指出的那样
将权限添加到清单以读取日志
<uses-permission android:name="android.permission.READ_LOGS" />
Run Code Online (Sandbox Code Playgroud)
小智 25
我会用这种东西:
$adb logcat -d > logcat.txt
Run Code Online (Sandbox Code Playgroud)
-d选项将整个循环缓冲区转储到文本文件中,如果您正在寻找特定的操作/意图,请尝试
$adb logcat -d | grep 'com.whatever.you.are.looking.for' -B 100 -A 100 > shorterlog.txt
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助 :)
jjh*_*okk 12
对于那些对USB调试或使用不感兴趣的人,adb有一个更简单的解决方案.在Android 6中(不确定先前版本),在开发人员工具下有一个选项:Take Bug Report
单击此选项将准备错误报告并提示您将其保存到驱动器或通过电子邮件发送.
我发现这是获取日志的最简单方法.我不想打开USB调试.
我常常得到错误" logcat read: Invalid argument".在从日志中读取之前,我必须清除日志.
我喜欢这个:
prompt> cd ~/Desktop
prompt> adb logcat -c
prompt> adb logcat | tee log.txt
Run Code Online (Sandbox Code Playgroud)
我知道这是一个老问题,但我相信即使在 2018 年仍然有效。
每个 Android 设备的开发者选项中都有一个隐藏的错误报告选项。
注意:这将转储整个系统日志
如何开启开发者选项?请参阅: https: //developer.android.com/studio/debug/dev-options
什么对我有用:
怎么读这个?打开bugreport-1960-01-01-hh-mm-ss.txt
你可能想寻找这样的东西:
------ SYSTEM LOG (logcat -v threadtime -v printable -d *:v) ------
--------- beginning of crash
06-13 14:37:36.542 19294 19294 E AndroidRuntime: FATAL EXCEPTION: main
Run Code Online (Sandbox Code Playgroud)
或者:
------ SYSTEM LOG (logcat -v threadtime -v printable -d *:v) ------
--------- beginning of main
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
273125 次 |
| 最近记录: |