답변:
Logcollector 는 좋은 옵션이지만 먼저 설치해야합니다.
로그 파일을 우편으로 보내려면 일반적으로 다음을 수행하십시오.
adb shell logcat > log.txtadb. 일반적으로C:\Users\[your username]\AppData\Local\Android\Sdk\platform-tools\
이 코드가 누군가를 돕기를 바랍니다. 장치에서 로깅하는 방법을 파악하고 필터링하는 데 2 일이 걸렸습니다.
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;
}
@mehdok가 지적한대로
로그 읽기 권한을 매니페스트에 추가
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_LOGS" />
편집하다:
내부 로그는 메모리의 순환 버퍼입니다. 라디오, 이벤트, 메인 각각에 대한 몇 가지 순환 버퍼가 실제로 있습니다. 기본값은 기본입니다.
버퍼의 복사본을 얻기 위해 한 가지 기술은 장치에서 명령을 실행하고 출력을 문자열 변수로 얻는 것입니다.
SendLog는 http://www.l6n.org/android/sendlog.shtml 을 수행하는 오픈 소스 앱입니다 .
핵심은 logcat임베디드 OS의 장치에서 실행 하는 것입니다. 들리는 것처럼 어렵지 않습니다. 링크에서 오픈 소스 앱을 확인하십시오.
간단한 방법은 자체 로그 수집기 방법을 만들거나 시장에서 기존 로그 수집기 앱을 만드는 것입니다.
내 응용 프로그램의 경우 로그를 내 전자 메일로 보내거나 다른 곳으로 보내는 보고서 기능을 만들었습니다. 로그를 얻은 후에는 원하는대로 할 수 있습니다.
다음은 장치에서 로그 파일을 얻는 방법에 대한 간단한 예입니다.
나는 그것이 오래된 질문이라는 것을 알고 있지만 2018 년에도 여전히 유효하다고 생각합니다.
모든 안드로이드 장치의 개발자 옵션 에 숨겨진 버그 보고서를 작성 하는 옵션이 있습니다 .
참고 : 이것은 전체 시스템 로그를 덤프합니다
개발자 옵션을 활성화하는 방법은 무엇입니까? 참조 : https://developer.android.com/studio/debug/dev-options
나를 위해 일하는 것 :
이것을 읽는 방법? 열린 버그 보고서-1960년 1월 1일-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
또는:
------ SYSTEM LOG (logcat -v threadtime -v printable -d *:v) ------
--------- beginning of main
user1354692 덕분에 한 줄로 더 쉽게 만들 수있었습니다! 그가 언급 한 것 :
try {
File file = new File(Environment.getExternalStorageDirectory(), String.valueOf(System.currentTimeMillis()));
Runtime.getRuntime().exec("logcat -d -v time -f " + file.getAbsolutePath());}catch (IOException e){}
OnCreate?
두 단계 :
- 로그 생성
- 로그를 보내려면 Gmail을로드하십시오.
.
로그 생성
File generateLog() {
File logFolder = new File(Environment.getExternalStorageDirectory(), "MyFolder");
if (!logFolder.exists()) {
logFolder.mkdir();
}
String filename = "myapp_log_" + new Date().getTime() + ".log";
File logFile = new File(logFolder, filename);
try {
String[] cmd = new String[] { "logcat", "-f", logFile.getAbsolutePath(), "-v", "time", "ActivityManager:W", "myapp:D" };
Runtime.getRuntime().exec(cmd);
Toaster.shortDebug("Log generated to: " + filename);
return logFile;
}
catch (IOException ioEx) {
ioEx.printStackTrace();
}
return null;
}로그를 보내려면 Gmail을로드하십시오.
File logFile = generateLog();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(logFile));
intent.setType("multipart/");
startActivity(intent);# 1에 대한 참조
~~
# 2의 경우 로그 파일을로드하여보고 보내는 방법에 대한 여러 가지 답변이 있습니다. 마지막으로 여기의 해결책은 실제로 두 가지 모두에 효과적이었습니다.
- 옵션으로 Gmail로드
- 파일을 성공적으로 첨부
올바르게 작동 하는 https://stackoverflow.com/a/22367055/2162226 에게 감사드립니다.
먼저 PATH를 android sdk platform-tools로 설정하여 adb 명령이 실행 가능한지 확인하십시오.
export PATH=/Users/espireinfolabs/Desktop/soft/android-sdk-mac_x86/platform-tools:$PATH
그런 다음 다음을 실행하십시오.
adb shell logcat > log.txt
또는 먼저 adb platform-tools로 이동하십시오.
cd /Users/user/Android/Tools/android-sdk-macosx/platform-tools
그런 다음 실행
./adb shell logcat > log.txt