appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
47 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IOSLog = void 0;
const node_events_1 = require("node:events");
const lru_cache_1 = require("lru-cache");
const support_1 = require("appium/support");
// We keep only the most recent log entries to avoid out of memory error
const MAX_LOG_ENTRIES_COUNT = 10000;
class IOSLog extends node_events_1.EventEmitter {
maxBufferSize;
logs;
_log;
constructor(opts = {}) {
super();
this.maxBufferSize = opts.maxBufferSize ?? MAX_LOG_ENTRIES_COUNT;
this.logs = new lru_cache_1.LRUCache({
max: this.maxBufferSize,
});
this._log = opts.log ?? support_1.logger.getLogger(this.constructor.name);
}
get log() {
return this._log;
}
async getLogs() {
const result = [];
for (const value of this.logs.rvalues()) {
result.push(this._deserializeEntry(value));
}
this._clearEntries();
return result;
}
_clearEntries() {
this.logs.clear();
}
broadcast(entry) {
const firstKey = this.logs.keys().next().value;
const recentIndex = typeof firstKey === 'number' ? firstKey : -1;
const serializedEntry = this._serializeEntry(entry);
this.logs.set(recentIndex + 1, serializedEntry);
if (this.listenerCount('output')) {
this.emit('output', this._deserializeEntry(serializedEntry));
}
}
}
exports.IOSLog = IOSLog;
exports.default = IOSLog;
//# sourceMappingURL=ios-log.js.map