Skip to content

Commit

Permalink
feat(bin): add tail option support to logcat
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Feb 20, 2025
1 parent cb21cd2 commit 029d72e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions libraries/android-bin/src/logcat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,17 @@ export interface LogcatFormatModifiers {
}

export interface LogcatOptions {
dump?: boolean;
pid?: number;
ids?: LogId[];
dump?: boolean | undefined;
pid?: number | undefined;
ids?: LogId[] | undefined;
tail?: number | Date | undefined;
}

function formatTailTime(date: Date) {
// Tail time supports multiple formats,
// `sssss.mmm` is simplest to implement
const timestamp = date.getTime();
return ((timestamp / 1000) | 0) + "." + (timestamp % 1000);
}

const NANOSECONDS_PER_SECOND = /* #__PURE__ */ BigInt(1e9);
Expand Down Expand Up @@ -503,6 +511,14 @@ export class Logcat extends AdbCommandBase {
if (options?.ids) {
args.push("-b", Logcat.joinLogId(options.ids));
}
if (options?.tail) {
args.push(
"-t",
typeof options.tail === "number"
? options.tail.toString()
: formatTailTime(options.tail),
);
}

// TODO: make `spawn` return synchronously with streams pending
// so it's easier to chain them.
Expand Down

0 comments on commit 029d72e

Please sign in to comment.