Skip to content

Device log

device.logs: the device log since the attach, and the steps that tie your own record to it. Guide: Device logs.

DeviceLog

The device log since the attachment opened (Device.logs): every logcat line of the main, system and crash buffers, with the actions Tap ran and the markers a test wrote in between, in the order they happened.

The server captures it from the moment the device is attached, unless the attachment turned that off (attach_device(capture_logs=False); every call here then raises ServerError with FailureReason.DAEMON_PRECONDITION). It reads the log while the device is attached; the server also keeps it after detach and restart, read with client.history. Secrets are replaced by <redacted> before the server stores a line and again on read: see redact.

Typical use, the app's warnings during one step::

device.logs.mark("checkout")
pay.tap()
errors = device.logs.read(since="checkout", packages=["com.shop"], min_priority="warn")
assert not errors.lines, errors.text

Methods:

Name Description
read

The entries so far, oldest first.

follow

The entries from the starting point and then every new one as it is logged, until

mark

Writes a named marker into the log, at the time the server gets the call, and

redact

Adds regular expressions (Java syntax) whose matches are replaced by <redacted>

read

read(*, since: str | int | LogEntry | None = None, tail: int | None = None, since_last_action: bool = False, packages: Iterable[str] = (), min_priority: LogPriority | str | None = None, tags: Iterable[str] = (), grep: str | None = None, actions: bool = True, step: str | None = None, until: str | int | LogEntry | None = None, timeout: float = 30.0) -> LogEntries

The entries so far, oldest first.

Where to start (at most one; none = the oldest entry the server still has): since a marker's name (from the newest marker with that name, raising ServerError with FailureReason.UNKNOWN_LOG_MARKER when there is none), a cursor or a LogEntry (what came after it); tail the newest N entries that pass the filters; since_last_action from the start of the newest action.

Filters, applied to logcat lines only (markers, actions and gaps always pass): packages keeps the lines of these apps, min_priority lines at least this severe (LogPriority or a name such as "warn"), tags lines with one of these tags, grep lines whose message contains a match of this regular expression (Java syntax, tested after redaction). actions=False leaves Tap's action entries out.

step narrows the read to one step (the id tap_e2e.step yielded): the entries from the step's first action to its last, nothing when it ran no action.

until ends the read there instead of now, that entry included: a marker's name (the newest marker with it among the entries read), a cursor or a LogEntry. A marker that is not among them, or a cursor before the first entry read, raises ValueError; so read(since="checkout", until="paid") is the stretch between two markers.

follow

follow(*, since: str | int | LogEntry | None = None, tail: int | None = None, since_last_action: bool = False, packages: Iterable[str] = (), min_priority: LogPriority | str | None = None, tags: Iterable[str] = (), grep: str | None = None, actions: bool = True) -> LogFollower

The entries from the starting point and then every new one as it is logged, until the returned LogFollower is closed or the device detached. Same starting points and filters as read, but the entries before now come from the newest 16 MiB the server keeps in memory (tail=1 starts near now); client.history reads older ones. Read it on its own thread, or to wait for a line::

with device.logs.follow(since="checkout", tags=["Payments"]) as log:
    done = next(e for e in log if e.line and "settled" in e.line.message)

A follower that reads too slowly is ended with ServerError (RESOURCE_EXHAUSTED); follow again since the last entry it got.

mark

mark(name: str, timeout: float = 30.0) -> int

Writes a named marker into the log, at the time the server gets the call, and returns its cursor. Read from it with read(since=name); a later marker with the same name replaces it as the starting point. name is 1 to 200 characters on one line. The server answers only once it has stored the marker.

redact

redact(*patterns: str, timeout: float = 30.0) -> None

Adds regular expressions (Java syntax) whose matches are replaced by <redacted> in everything read from now on, lines already captured included: by read and follow, Device.device_logs() and the failure artifacts. A match is replaced whole; a pattern with a capturing group has only its first group replaced (r"session=(\w+)" keeps session=).

Redacted without any call: Authorization / Cookie style headers, password= / token= style values, bearer tokens, JWTs, and the text of every sensitive set_text / type_text on this device (literals of four characters or longer). At most 64 patterns per attachment. A new pattern also rewrites what the server has already stored of this attachment, its calls and crashes included (a failed rewrite is an error); it cannot erase copies you saved or exported before.

LogEntries

Bases: list[LogEntry]

What DeviceLog.read returns: the entries, oldest first.

clock_id

clock_id: str

The server run whose monotonic clock LogEntry.host_monotonic_ns is on.

capture_error

capture_error: str

Why the server could not keep all of this attachment's log (a storage limit or failure); empty when it kept everything.

dropped

dropped: int

How many entries of the requested range the server no longer has (its retention removed them), counted before the filters. Always 0 for a tail read.

text

text: str

The entries as text, one per line.

lines

lines: list[LogLine]

The logcat lines among the entries.

messages

messages: list[str]

The message of each logcat line.

LogEntry

One entry of the device log: exactly one of line, marker, action and gap is set. str(entry) is the entry as one line of text, led by at in the local time zone (MM-DD HH:MM:SS.mmm, the clock of every other Tap record; the device's own clock can be far off); a line then has uid, pid, tid, priority, tag and message, like logcat -v threadtime.

cursor

cursor: int

1, 2, 3, … per attachment, in the order the server got the entries. Pass it as since to read what came after.

at

at: float

The server host's clock when it got the entry (Unix seconds), the clock of LoggedEvent.at.

line

line: LogLine | None

marker

marker: str | None

The name given to DeviceLog.mark.

action

action: LogAction | None

gap

gap: str | None

The capture was interrupted here (the device disconnected, logcat ended) and lines may be missing: why.

host_monotonic_ns

host_monotonic_ns: int

The server's monotonic clock when it got the entry; compare it only within one LogEntries.clock_id.

summary

summary: str

A marker, gap or action as ── marker NAME, ── gap WHY or ── tap TARGET → ok 243 ms; a line as P Tag: message. No time.

LogLine

One logcat line. A message of several lines arrives as several entries.

device_time

device_time: float

The device's clock when the line was logged (Unix seconds); it need not agree with the host's.

uid

uid: int | None

The Linux uid of the process that logged it; None when logcat printed no number.

pid

pid: int

tid

tid: int

priority

priority: LogPriority | None

tag

tag: str

message

message: str

packages

packages: tuple[str, ...]

The apps installed under uid: one for an app, several for apps sharing a uid, none for a system process or an app no longer installed.

packages_observed_at

packages_observed_at: float | None

When the server looked up packages (Unix seconds); None when the line was saved without them, so empty packages then means "not known", not "a system process".

LogAction

Something Tap did on the device: one entry when it starts and one when it finishes.

A command the driver runs (a tap, typed text, a wait) is logged by the driver itself, so its entries are ordered exactly among the app's lines; queries (exists, count, a snapshot) are left out. A call the host runs over ADB (an app launch, a device setting) is written by the server when the call starts and ends.

operation

operation: str

The operation in snake_case: tap, wait_visible, launch, set_network.

target

target: str | None

What it acted on: a command's selector, an app call's package. Never typed text.

finished

finished: bool

outcome

outcome: str | None

With finished: ok, a command error code (NOT_FOUND) or a failure reason.

duration

duration: float | None

With finished: how long it took, in seconds.

request_id

request_id: int | None

Driver commands: the request the driver answered.

step

step: str | None

The step the call that caused it was made in (tap_e2e.step), or None.

LogPriority

Bases: IntEnum

A logcat priority; a higher value is more severe.

Methods:

Name Description
of

value itself, or the priority a name or letter stands for ("warn", "W").

VERBOSE

VERBOSE

DEBUG

DEBUG

INFO

INFO

WARN

WARN

ERROR

ERROR

FATAL

FATAL

letter

letter: str

The letter logcat prints: V, D, I, W, E or F.

of

of(value: LogPriority | str) -> LogPriority

value itself, or the priority a name or letter stands for ("warn", "W").

LogFollower

The live device log (DeviceLog.follow): iterate it for entries as the server gets them. Iteration blocks until the next entry and ends when the device is detached or close() is called (from any thread); use it as a context manager to close it.

Methods:

Name Description
close

Stops following; an iteration in progress ends.

capture_error

capture_error: str

clock_id

clock_id: str

dropped

dropped: int

How many entries older than the starting point the server had already forgotten; known once the first entry has been read.

close

close() -> None

Stops following; an iteration in progress ends.

History and recordings

client.history: the server's kept history, also after the connection ended, and named recordings of it. Guide: History after the script.

History

The server's history (client.history). It needs no live connection or attachment: read it from a test's teardown, after a crash or from another process.

Typical use, what one test did, with the app's warnings::

page = client.history.read(connections=[connection], since_marker="test checkout",
                           logs=True, min_priority="warn")
print(page.text)

The server keeps history under its retention policy; keep a range past it with start_recording / stop_recording.

Methods:

Name Description
read

One page of history, oldest first (newest_first: the most recent limit

resume

The page after cursor (a HistoryPage.next_cursor), of the read it came from: same selection, bounds, filters and order. A cursor keeps

pages

Every page of a read with these arguments, in order.

sources

The kept sources, of ended connections and detached devices too, selected as in

start_recording

Keeps connection's history from now on, devices it attaches later included,

stop_recording

Ends the recording's range, also after its connection ended; stopping it again

recordings

The recordings of these connections (all when none is given), stopped or not.

delete_recording

Deletes a stopped recording; retention may then remove its entries. Files saved

read

read(*, connections: Iterable[TapConnection | str] = (), sources: Iterable[HistorySource | str] = (), serials: Iterable[str] = (), recording: HistoryRecording | str | None = None, since: float | datetime | str | None = None, until: float | datetime | str | None = None, since_marker: str | None = None, until_marker: str | None = None, step: str | None = None, logs: bool = False, packages: Iterable[str] = (), min_priority: LogPriority | str | None = None, tags: Iterable[str] = (), grep: str | None = None, actions: bool = True, driver_lines: bool = False, newest_first: bool = False, limit: int = 200, timeout: float = 30.0) -> HistoryPage

One page of history, oldest first (newest_first: the most recent limit entries of the range first).

Selection (each given one must match): connections (TapConnection or id), sources, device serials (their logs, calls and deaths) and a recording's range. Nothing selects all the server keeps.

since / until: a time, as Unix seconds, an aware datetime or an ISO 8601 string with its offset ("2026-11-21T12:00:00Z"); since is included, until not. since_marker / until_marker instead: from or through the newest marker with that name on each selected device, the marker included (ServerError UNKNOWN_LOG_MARKER when none). Select connections too to leave out other connections' markers of the same name. Without an end the read ends when it starts, so its pages never move.

step keeps what happened in that step (tap_e2e.step): its calls, the deaths and gaps between the start of its first call and the end of its last, and each device log from its first action to its last; a name used again after another step adds a second such stretch. The bounds still apply.

Calls, deaths and gaps are always read; logs=True adds the device logs, which packages, min_priority, tags, grep (Java regex), actions and driver_lines filter (they never drop gaps, calls or deaths).

resume

resume(cursor: str, *, limit: int = 200, timeout: float = 30.0) -> HistoryPage

The page after cursor (a HistoryPage.next_cursor), of the read it came from: same selection, bounds, filters and order. A cursor keeps working in another process and after a server restart, not across server versions.

pages

pages(**read_arguments: Any) -> Iterator[HistoryPage]

Every page of a read with these arguments, in order.

sources

sources(*, connections: Iterable[TapConnection | str] = (), sources: Iterable[HistorySource | str] = (), serials: Iterable[str] = (), recording: HistoryRecording | str | None = None, timeout: float = 30.0) -> tuple[HistorySource, ...]

The kept sources, of ended connections and detached devices too, selected as in read.

start_recording

start_recording(connection: TapConnection | str, name: str, *, timeout: float = 30.0) -> HistoryRecording

Keeps connection's history from now on, devices it attaches later included, until the recording is stopped and deleted. It stops by itself when the connection closes. A device whose capture already failed is included with an INCOMPLETE issue. name: 1 to 80 ASCII letters, digits, dots, dashes and underscores, unique among the connection's recordings.

stop_recording

stop_recording(recording: HistoryRecording | str, *, timeout: float = 30.0) -> HistoryRecording

Ends the recording's range, also after its connection ended; stopping it again returns it unchanged. Calls still running then are a gap at its end.

recordings

recordings(*, connections: Iterable[TapConnection | str] = (), timeout: float = 30.0) -> tuple[HistoryRecording, ...]

The recordings of these connections (all when none is given), stopped or not.

delete_recording

delete_recording(recording: HistoryRecording | str, *, timeout: float = 30.0) -> None

Deletes a stopped recording; retention may then remove its entries. Files saved separately are not touched.

HistoryPage

Bases: Artifact

One page of History.read: its entries in the order read, the sources it covered and the evidence that is missing. Iterating it yields the entries; next_page() reads the next page. As an Artifact its bytes are to_json().

Methods:

Name Description
next_page

The next page of the same read, or None after the last.

render_text

text; with details crash stack traces too.

to_dict

JSON-ready, as tap-history/2: entries, sources, issues, through,

to_json

entries

entries: tuple[HistoryEntry, ...]

sources

sources: tuple[HistorySource, ...]

issues

issues: tuple[HistoryIssue, ...]

Every issue of the read, each once, the sources' own included.

next_cursor

next_cursor: str | None

None when this is the last page.

through

through: float

The read's end (exclusive), in Unix seconds, fixed by its first page.

media_type

media_type

extension

extension

text

text: str

The entries one per line (HistoryEntry.text), then a WARNING: line per issue.

bytes

bytes: bytes

next_page

next_page(limit: int | None = None) -> HistoryPage | None

The next page of the same read, or None after the last.

render_text

render_text(*, details: bool = False) -> str

text; with details crash stack traces too.

to_dict

to_dict() -> dict[str, Any]

JSON-ready, as tap-history/2: entries, sources, issues, through, next_cursor.

to_json

to_json() -> str

HistoryEntry

One thing that happened: exactly one of line, action, marker (a device log), call, death (a connection) and gap (either) is set.

Methods:

Name Description
text

AT SERIAL SUMMARY; with details a crash's stack trace follows, one | line

to_dict

JSON-ready: identity, times (at ISO 8601 UTC, monotonic_ns a string) and the

source_id

source_id: str

sequence

sequence: int

1, 2, 3, … per source, in the order the server received the entries.

at

at: float

When the server received it, in Unix seconds: for a call, when it ended (call.at is when it began). Pages are ordered by this, then by source, then by sequence.

monotonic_ns

monotonic_ns: int

The server's monotonic clock at receipt, comparable within one HistorySource.clock_id.

serial

serial: str | None

The device: the source's, a call's or a death's; None for a gap of a connection.

line

line: LogLine | None

action

action: LogAction | None

marker

marker: str | None

call

call: LoggedEvent | None

death

death: AppDeath | None

gap

gap: str | None

Capture stopped here and entries may be missing until it resumed: why.

kind

kind: str

line, action, marker, call, death or gap.

summary

summary: str

The entry as one line without its time or device: W Tag: message, ── tap …, ── marker NAME, call exists text("Pay") → ok, CRASH com.shop (pid 4) …, GAP: why.

text

text(*, details: bool = False) -> str

AT SERIAL SUMMARY; with details a crash's stack trace follows, one | line each.

to_dict

to_dict() -> dict[str, Any]

JSON-ready: identity, times (at ISO 8601 UTC, monotonic_ns a string) and the entry's own fields under its kind.

HistorySource

Something the server keeps history of: one attachment's device log (attached_device_id and serial set), or one connection's calls and the crashes and ANRs on its devices (both None).

Methods:

Name Description
to_dict

id

id: str

connection_id

connection_id: str

serial

serial: str | None

clock_id

clock_id: str

The server run that captured it: compare HistoryEntry.monotonic_ns only within it.

closed

closed: bool

The connection ended or the device was detached: nothing more will be added.

last_sequence

last_sequence: int

From History.sources, the newest entry's sequence; in a HistoryPage, the newest one the read covers, fixed by its first page.

retained_bytes

retained_bytes: int

Bytes on disk, some possibly shared with other sources.

issues

issues: tuple[HistoryIssue, ...]

From History.sources only; a HistoryPage has every issue in HistoryPage.issues.

is_device_log

is_device_log: bool

to_dict

to_dict() -> dict[str, Any]

HistoryIssue

Evidence that is missing without a place in time. Where capture stopped and resumed is a gap entry instead.

Methods:

Name Description
to_dict

kind

message

message: str

Short and readable, never a trace or a command's output.

source_id

source_id: str | None

The source it is about; None for a recording's own storage problem.

missing_entries

missing_entries: int

For EXPIRED: how many of the source's entries were removed, counted before filters; 0 when the server does not know.

to_dict

to_dict() -> dict[str, Any]

HistoryIssueKind

Bases: Enum

What evidence is missing (HistoryIssue.kind).

EXPIRED

EXPIRED

The server's retention removed entries the read asked for: the range starts before what is kept, entries in it passed the retention age, or entries went while paging. A read without since starts at the oldest kept entry and so reports none for that.

UNAVAILABLE

UNAVAILABLE

A requested or recorded source is not kept or could not be read.

INCOMPLETE

INCOMPLETE

The server could not keep all of the source (a storage limit or failure, a torn write), or withholds its kept entries because a redaction could not be applied to them.

PACKAGE_UNKNOWN

PACKAGE_UNKNOWN

Some lines were stored without their app, so a package filter returned them unfiltered.

UNKNOWN

UNKNOWN

A kind this client does not know yet.

HistoryRecording

A range of one connection's history the server keeps past its retention policy, until History.delete_recording. It covers the connection's devices, also those attached after it started.

Methods:

Name Description
to_dict

id

id: str

Names it in read(recording=…) and every control, also after its connection ended.

connection_id

connection_id: str

name

name: str

Unique among the connection's recordings, not across the server.

started_at

started_at: float

stopped_at

stopped_at: float | None

None while recording.

spans

spans: tuple[HistorySpan, ...]

issues

issues: tuple[HistoryIssue, ...]

retained_bytes

retained_bytes: int

Bytes on disk its spans need; others may share them, so deleting it can free less.

active

active: bool

Still recording: not stopped yet.

to_dict

to_dict() -> dict[str, Any]

HistorySpan

The part of one source a recording keeps: after after_sequence, through through_sequence (None while recording).

source_id

source_id: str

after_sequence

after_sequence: int

through_sequence

through_sequence: int | None

Steps

step

step(step_id: str | None = None) -> Iterator[str]

Runs the block as one step and yields the step's id.

Every call made to the server inside the block, on this thread, carries the id. The server copies it to the actions the calls cause in the device log (LogAction.step) and to their events (LoggedEvent.step), so a caller that keeps its own record of steps can find what each one did on the device::

with tap_e2e.step() as checkout:
    cart.tap()
    pay.tap()
log = device.logs.read(step=checkout)   # from its first action to its last

step_id is 1 to 64 of A-Z a-z 0-9 . _ -; without one a new id is made. A step inside a step replaces it until the inner block ends.

current_step

current_step() -> str | None

The id of the step this thread (or task) is in, or None outside step().