LinuxCommandLibrary

logcat

View Android system logs

TLDR

Display system logs

$ logcat
copy

Write system logs to a file

$ logcat -f [path/to/file]
copy

Display lines that match a regex

$ logcat --regex [regex]
copy

SYNOPSIS

`logcat [options] [filterspecs]`

PARAMETERS

-b
    View an alternate log buffer, such as radio, events, main, system, crash, default. default buffer shows all of the log messages

-c
    Clear the entire log and exit.

-d
    Dump the log to the screen and exit.

-f
    Log to a file. Default is stdout.

-g
    Rotate the log every size kilobytes. The default is 16, if size is omitted.

-n
    Sets the number of rotated logs to be maintained, default 4.

-r
    Rotate every kbytes of output, implies -f.

-s
    Set default filter to silent. Like adding *:S to the filter list.

-S
    Print statistics.

-t
    Print only the most recent number lines.

-t '
    Print lines after the specified time. Format: MM-DD hh:mm:ss.milliseconds or yyyy-MM-DD hh:mm:ss.milliseconds

-T
    Print only the most recent number lines.

-T '
    Print lines after the specified time. Format: MM-DD hh:mm:ss.milliseconds or yyyy-MM-DD hh:mm:ss.milliseconds

-v
    Sets the log output format. Options include brief, long, process, raw, tag, thread, threadtime, time, usec, epoch.


    A filterspec is a tag[:priority] specification.
Tag is the source code tag of the message.
Priority is one of the following characters: V Verbose, D Debug, I Info, W Warn, E Error, F Fatal, S Silent (highest priority, on which nothing is ever printed).

DESCRIPTION

The `logcat` command is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages written from your application with the `Log` class. It provides a mechanism for collecting and viewing system debug output. This is crucial for debugging Android applications, analyzing system behavior, and diagnosing issues on Android devices or emulators. The output from `logcat` contains a stream of log entries, each with timestamp, priority, tag, and the log message. Filtering options are available to focus on specific applications, log levels, or components. Understanding the log output helps developers identify bugs, performance bottlenecks, and unexpected application behavior. Developers often use `logcat` to trace the execution flow of their applications, monitor resource usage, and observe interactions with the Android framework. It is an indispensable tool for Android development and troubleshooting.

CAVEATS

Requires ADB (Android Debug Bridge) to be set up and the device to be connected.
Permissions might be needed to access specific logs, depending on the Android version and device configuration.

FILTERING LOG OUTPUT

Filterspecs can be used to limit the log output to specific tags and priorities. For example: `logcat MyApp:D *:S` will show all Debug messages from the tag "MyApp" and suppress all other messages. The `*:S` part is important since the priority is global.

LOG PRIORITIES

Log priorities represent the severity level of a log message. V (Verbose) is the lowest priority, followed by D (Debug), I (Info), W (Warn), E (Error), and F (Fatal). S (Silent) suppresses all logging.

OUTPUT FORMATS

The `-v` option controls the format of the log output. Different formats provide varying levels of detail. `threadtime` is a commonly used format, showing timestamp, thread ID, priority, tag, and message.

HISTORY

Introduced as part of the Android SDK, evolving alongside the Android operating system. Its primary function has always been providing a way to view system logs for debugging and analysis. The format and options have been modified over time to improve functionality and flexibility.

SEE ALSO

adb(1)

Copied to clipboard