← Logcat
Logcat·Guide
All tools

The Logcat tool

Android logs in the threadtime format, the default of adb logcat (and adb logcat -v threadtime, and the logcat sections of bug reports). Drop or paste a file, or send one from the ADB page. Everything runs in your browser and nothing is uploaded.

01-15 10:23:45.123  1234  1250 I ActivityManager: Start proc 4321:com.example.notes/u0a123 …

Contents

  1. The Logcat library

1The Logcat library

lib/logcat.js is a JavaScript module that reads logcat text into entries. It has no dependencies and no user interface, so it also runs in a module Web Worker or in jsc. It exports one class, Logcat, whose methods are all static:

import { Logcat } from "../lib/logcat.js";
MethodWhat it does
Logcat.parse(text){ entries, processNames }. Each entry is { kind: "log", monthDay, time, timestamp, pid, tid, level, tag, message, raw } or, for “beginning of” lines, { kind: "divider", text, raw }. Continuation lines are added to the message (and raw) before them; one before any header is an entry of its own with level "I" and empty fields.
Logcat.processNames(text)A Map from pid to process name, from “Start proc”, libc and “Process: …, PID: …” lines.
Logcat.processes(entries, processNames)[{ pid, name, count }], the processes with the most lines first.
Logcat.timestamps(entries)The distinct timestamps ("01-15 10:23:45.123"), sorted.
Logcat.isLogcat(text)True when some line starts like a threadtime header or a “beginning of” divider.
Logcat.LEVELS, Logcat.LEVEL_NAMES["V", "D", "I", "W", "E", "F"], and their names (plus S, Silent).
import { Logcat } from "../lib/logcat.js";

const { entries, processNames } = Logcat.parse(text);
const crashes = entries.filter(entry => entry.kind === "log" && entry.tag === "AndroidRuntime" && entry.level === "E");
for (const entry of crashes) {
	console.log(entry.timestamp, processNames.get(entry.pid) || entry.pid, entry.message);
}

Timestamps carry no year, so they sort correctly within one year only.