“This is the 18th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”
Resolve ADB Logcat help information
octopus@octopus:~$ adb logcat --help Usage: logcat [options] [filterspecs] options include: -s Set default filter to silent. Like specifying filterspec '*:s' -f <filename> Log to file. Default to stdout -r [<kbytes>] Rotate log every kbytes. (16 if unspecified). Requires -f -n <count> Sets max number of rotated logs to <count>, default 4 -v <format> Sets the log print format, where <format> is one of: brief process tag thread raw time threadtime long -c clear (flush) the entire log and exit -d dump the log and then exit (don't block) -t <count> print only the most recent <count> lines (implies -d) -g get the size of the log's ring buffer and exit -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio' or 'events'. Multiple -b parameters are allowed and the results are interleaved. The default is -b main -b system. -B output the log in binary filterspecs are a series of <tag>[:priority] where <tag> is a log component tag (or * for all) and priority is: V Verbose D Debug I Info W Warn E Error F Fatal S Silent (supress all output) '*' means '*:d' and <tag> by itself means <tag>:v If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS. If no filterspec is found, filter defaults to '*:I' If not specified with -v, format is set from ANDROID_PRINTF_LOG or defaults to "brief"Copy the code
Adb logcat command format: adb logcat [options] [filter], where options and filters in brackets [], indicating that this is optional;
A. the b. the C. the D. the
— “-s” option: Set the label of the output log. Only the logs of this label are displayed.
— “-f” option: output logs to a file, default output to the standard output stream, -f parameter execution failed;
— “-r” option: output logs per kilobyte. -f is required, but this command was not executed successfully.
— “-n” option: set the maximum number of logs to be output, requires the -r argument, this execution feels like adb logcat;
— “-v” option: Set only one log output format.
— “-c” option: clear all log cache information;
— “-d” option: outputs cached logs to the screen without blocking;
— “-t” option: output the last few lines of the log, exit after output, not blocking;
— “-g” option: view log buffer information;
— “-b” option: load a log buffer. Default is main.
— “-b” option: output logs in binary format.
Output the content of the specified label:
— “-s” option: Set the default filter. If we want to output “system. out” tag information, we can use adb logcat -s system. out command;
octopus@octopus:~$ adb logcat -s System.out
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/System.out(22930): GSM -91
I/System.out(22930): SignalStrength issssssssss : -91
I/System.out(22930): GSM -91
I/System.out(22930): SignalStrength issssssssss : -91
I/System.out(22930): Supervisor Thread
I/System.out(22930): Got run mode
Copy the code
Output log information to a file:
— “>” Output: “>” To output the log file, you can output the logcat log file to the file. Run adb logcat > log to view the log information.
octopus@octopus:~$ adb logcat > log
^C
octopus@octopus:~$ more log
--------- beginning of /dev/log/system
V/ActivityManager( 500): We have pending thumbnails: null
V/ActivityManager( 500): getTasks: max=1, flags=0, receiver=null
V/ActivityManager( 500): com.android.settings/.Settings: task=TaskRecord{42392278 #448 A com.android.settings U 0}
V/ActivityManager( 500): We have pending thumbnails: null
Copy the code
Specify logcat log output format:
— “-v” option: use adb logcat -v time to check the output time of the log.
— “brief” format: this is the default log format “priority/label (process ID) : log message”, use adb logcat -v prief command;
octopus@octopus:~$ adb logcat -v brief
--------- beginning of /dev/log/system
D/PowerManagerService( 500): handleSandman: canDream=true, mWakefulness=Awake
D/PowerManagerService( 500): releaseWakeLockInternal: lock=1101267696, flags=0x0
Copy the code
Clearing log cache information:
Run the ADB logcat -c command to clear previous logs and output logs again.
Output cache logs:
Adb logcat -d adb logcat -d adb logcat -d adb logcat -d
Filter Item Parsing
[:priority], tag: log level. The default log filtering item is “*:I”.
— V: Verbose;
— D: Debug;
— I: Info;
— W: Warn;
— E: Error;
— F: Fatal;
— S: Silent(Super all output);
Use pipes to filter logs
Filtering fixed strings
All logs from the command line can be filtered, regardless of tags.
– command: adb logcat | grep Wifi.
octopus@octopus:~$ adb logcat | grep Wifi
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
Copy the code
Filter string ignore case: adb logcat | grep -i wifi.
Use regular expression matching
Parse the log: the first two characters of the log are “V/”, followed by a label, write a regular expression “^.. ActivityManager”, matches the “V/ActivityManager” string in the log;
V/ActivityManager( 574): getTasks: max=1, flags=0, receiver=null
Copy the code
Regular expression to filter the log: use the above regular expression of the adb logcat command | grep “^.. Activity” ;