A LogCat = a summary of every action you perform on the Android device + a system log of everything going on in the background.
Use LogCat from within DDMS or call it on an ADB shell.
[adb] logcat [option]... [filter-spec]...
Use adb logcat -c
to clear the log buffer. This will reset the log and only logs after the reset will be shown.
Output to a file:
adb logcat > log.txt
or
adb logcat -f log.txt
The best way to save:
adb logcat *:W -v long > log.txt
with the -v flag & the long argument, it changes output to long style, which means every line of logcat will be on its own line *:W – a filter that outputs only serious errors.Clear the log buffer. Run the command, then try to reproduce whatever your problem is while the log is running.
Press CTRL + C to end the logcat after you’ve reproduced the error.
Advanced usage
1. Filtering
- By priority
adb logcat
offers extra functionality to filter logs based on priority. The usage is adb logcat *:#
where #
is one of the following.
– V (Verbose) – show all possibly useless logs, default level;
– D (Debug) – show all reasonable debug logs;
– I (Info) – show expected logs for regular usage;
– W (Warn) – show possible issues that are not yet errors;
– E (Error) – show issues that have caused errors;
– F (Fatal) – show issues that are fatal to runtime and will often result in rebooting.
All priorities automatically include higher priorities, so adb logcat *:W
will show warnings, errors and fatal errors. When an app crashes, for example, you can usually use adb logcat *:E
to see the cause of the issue without having to look through irrelevant debug logging. However, when providing logs to developers make sure to include all logging (without any filtering tag) because debugging logs can often explain the error.
- By Content
$ adb logcat | grep Google
This command takes the output of “logcat” (all the junk) and “pipes” it to the grep
command, which is used to search for “Google” and will only return lines that include it.
$ adb logcat | grep -i Google
This will return log lines that have “Google”, “google”, “gOoGlE” and any other combination of upper and lowercase characters.
2. Controlling Log Output Format
adb logcat -v <format>
brief |
Display priority/tag and PID of the process issuing the message (the default format). |
process |
Display PID only. |
tag |
Display the priority/tag only. |
raw |
Display the raw log message, with no other metadata fields. |
time |
Display the date, invocation time, priority/tag, and PID of the process issuing the message. |
threadtime |
Display the date, invocation time, priority, tag, and the PID and TID of the thread issuing the message. |
long |
Display all metadata fields and separate messages with blank lines. |
3. Doing other useful stuff
– d | Dumps the log to the screen and exits. | |
– b | <buffer> |
The Android logging system keeps multiple circular buffers for log messages, and not all of the log messages are sent to the default circular buffer. There are 3 alternate log buffers on the Android system:main (default)<events> <radio> |
– g | Prints the size of the specified log buffer and exits. | |
– n | <count> |
Sets the maximum number of rotated logs to <count> . The default value is 4. Requires the -r option. |
– r | <kbytes> |
Rotates the log file every <kbytes> of output. The default value is 16. Requires the -f option. |
– f | <file> |
Writes log message output to a file. The default is the “stdout – Standard Output”. |
– s | Sets the default filter spec to silent. |
4. Coloring
adb logcat -C
can be used to show logs with color to make them easier to read when viewing (for Android 4.1 and above).
Some External color logcat scripts: