adb shell logcat

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 --help
Usage: logcat [options] [filterspecs]

General options:
  -b, --buffer=       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
                              'security' for Device Owner installations.
                              Multiple -b parameters or comma separated list of buffers are
                              allowed. Buffers are interleaved.
                              Default -b main,system,crash,kernel.
  -L, --last                  Dump 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 rotated
                              log files instead.
                              if -L is specified, clear pstore log instead.
  -d                          Dump the log and then exit (don't block).
  --pid=                 Only print logs from the given pid.
  --wrap                      Sleep for 2 hours or when buffer about to wrap whichever
                              comes first. Improves efficiency of polling by providing
                              an 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 time
                              Modifying adverbs can be added:
                                color descriptive epoch monotonic printable uid usec UTC year zone
                              Multiple -v parameters or comma separated list of format and format
                              modifiers are allowed.
  -D, --dividers              Print dividers between each log buffer.
  -B, --binary                Output 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 the
                              associated 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, --statistics            Output 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 pruned
                              with higher priority otherwise they're pruned with lower priority. All
                              other pruning activity is oldest first. Special case ~! represents an
                              automatic pruning for the noisiest UID as determined by the current
                              statistics.  Special case ~1000/! represents pruning of the worst PID
                              within AID_SYSTEM when AID_SYSTEM is the noisiest UID.
  -P, --prune=' ...'    Set prune rules, using same format as listed above. Must be quoted.

Filtering:
  -s                          Set default filter to silent. Equivalent to filterspec '*:S'
  -e, --regex=          Only print lines where the log message matches  where  is
                              an 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 not
                              match the regex. Logcat will quit after printing the max-count number
                              of lines that match the regex.
  -t                   Print only the most recent  lines (implies -d).
  -t '

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 参考资料

你可能感兴趣的:(adb命令,adb,shell,logcat)