1 需求

  • 打印指定包名的log
    • adb shell logcat -d -b main -s PRIVA_LOG –pid `pidof com.android.phone`
    • adb shell logcat -d -b main -s PRIVA_LOG –pid=$(“pidof com.android.phone”)

2 语法

C:\>adb logcat --helpUsage: logcat [options] [filterspecs]General options:-b, --buffer= Request alternate ring buffer(s):main system radio events crash default allAdditionally, 'kernel' for userdebug and eng builds, and'security' for Device Owner installations.Multiple -b parameters or comma separated list of buffers areallowed. Buffers are interleaved.Default -b main,system,crash,kernel.-L, --lastDump logs from prior to last reboot from pstore.-c, --clear Clear (flush) the entire log and exit.if -f is specified, clear the specified file and its related rotatedlog files instead.if -L is specified, clear pstore log instead.-dDump the log and then exit (don't block).--pid= Only print logs from the given pid.--wrapSleep for 2 hours or when buffer about to wrap whichevercomes first. Improves efficiency of polling by providingan about-to-wrap wakeup.Formatting:-v, --format= Sets log print format verb and adverbs, where  is one of:brief help long process raw tag thread threadtime timeModifying adverbs can be added:color descriptive epoch monotonic printable uid usec UTC year zoneMultiple -v parameters or comma separated list of format and formatmodifiers are allowed.-D, --dividersPrint dividers between each log buffer.-B, --binaryOutput the log in binary.Outfile files:-f, --file= Log to file instead of stdout.-r, --rotate-kbytes= Rotate log every  kbytes. Requires -f option.-n, --rotate-count=Sets max number of rotated logs to , default 4.--id= If the signature  for logging to file changes, then clear theassociated files and continue.Logd control: These options send a control message to the logd daemon on device, print its return message if applicable, then exit. They are incompatible with -L, as these attributes do not apply to pstore.-g, --buffer-size Get the size of the ring buffers within logd.-G, --buffer-size=Set size of a ring buffer in logd. May suffix with K or M.This can individually control each buffer's size with -b.-S, --statisticsOutput statistics.--pid can be used to provide pid specific stats.-p, --prune Print prune rules. Each rule is specified as UID, UID/PID or /PID. A'~' prefix indicates that elements matching the rule should be prunedwith higher priority otherwise they're pruned with lower priority. Allother pruning activity is oldest first. Special case ~! represents anautomatic pruning for the noisiest UID as determined by the currentstatistics.Special case ~1000/! represents pruning of the worst PIDwithin AID_SYSTEM when AID_SYSTEM is the noisiest UID.-P, --prune=' ...'Set prune rules, using same format as listed above. Must be quoted.Filtering:-sSet default filter to silent. Equivalent to filterspec '*:S'-e, --regex=Only print lines where the log message matches  where  isan ECMAScript regular expression.-m, --max-count= Quit after printing  lines. This is meant to be paired with--regex, but will work on its own.--print This option is only applicable when --regex is set and only useful if--max-count is also provided.With --print, logcat will print all messages even if they do notmatch the regex. Logcat will quit after printing the max-count numberof lines that match the regex.-t Print only the most recent  lines (implies -d).-t '' Print the lines since specified time (implies -d).-T Print only the most recent  lines (does not imply -d).-T '' Print the lines since specified time (not imply -d).count is pure numerical, time is 'MM-DD hh:mm:ss.mmm...''YYYY-MM-DD hh:mm:ss.mmm...' or 'sssss.mmm...' format.--uid=Only display log messages from UIDs present in the comma separate list. No name look-up is performed, so UIDs must be provided asnumeric values. This option is only useful for the 'root', 'log', and'system' users since only those users can view logs from other users.filterspecs are a series of[:priority]where  is a log component tag (or * for all) and priority is:VVerbose (default for )DDebug (default for '*')IInfoWWarnEErrorFFatalSSilent (suppress all output)'*' by itself means '*:D' and  by itself means :V.If no '*' filterspec or -s on command line, all filter defaults to '*:V'.eg: '*:S ' prints only , ':S' suppresses all  log messages.If not specified on the command line, filterspec is set from ANDROID_LOG_TAGS.If not specified with -v on command line, format is set from ANDROID_PRINTF_LOGor defaults to "threadtime"

3 示例:打印指定包名的log

adb shell logcat -d -b main -s PRIVA_LOG –pid `pidof com.android.phone`

adb shell logcat -d -b main -s PRIVA_LOG –pid=$(“pidof com.android.phone”)

adb logcat -d -b main -s PRIVA_LOG –pid `pidof com.android.phone`

adb logcat -d -b main -s PRIVA_LOG –pid=$(“pidof com.android.phone”)


4 参考资料