UNPKG

logkitten

Version:

Stream Android and iOS logs without Android Studio or Console.app, with programmatic Node.js API for log analysis.

62 lines (61 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IosParser = void 0; var _utils = require("../utils"); var _utils2 = require("./utils"); function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } class IosParser { constructor() { _defineProperty(this, "_buffer", new _utils.LineBuffer()); this.parse = this.parse.bind(this); } static create() { const parser = new IosParser(); return parser.parse.bind(parser); } parse(raw, stderr) { const str = typeof raw === 'string' ? raw : raw.toString('utf-8'); const lines = this._buffer.processChunk(str); return lines.flatMap(line => this._parseLine(line, stderr)); } _parseLine(line, stderr) { if (stderr) { return this._parseStderr(line); } let rawEntry; try { rawEntry = JSON.parse(line); } catch { return []; } const entry = { msg: rawEntry.eventMessage, ts: Date.parse(rawEntry.timestamp), pid: rawEntry.processID, tid: rawEntry.threadID, level: _utils2.PriorityUtils.fromName(rawEntry.messageType), // Platform specific fields category: rawEntry.category, formatString: rawEntry.formatString, processImagePath: rawEntry.processImagePath, subsystem: rawEntry.subsystem, userID: rawEntry.userID }; return [entry]; } _parseStderr(line) { if (line.includes('No devices are booted.')) { throw new Error('No simulators are booted.'); } if (line.includes('getpwuid_r did not find a match for uid')) { return []; } throw new Error(line); } } exports.IosParser = IosParser; //# sourceMappingURL=parser.js.map