UNPKG

@axiomhq/logging

Version:
41 lines (40 loc) 1.38 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; import { Axiom, AxiomWithoutBatching } from "@axiomhq/js"; import { LogLevelValue, LogLevel } from "../logger.js"; class AxiomJSTransport { constructor(config) { __publicField(this, "config"); __publicField(this, "promises", []); this.config = config; } log(logs) { const filteredLogs = logs.filter( (log) => LogLevelValue[log.level ?? LogLevel.info] >= LogLevelValue[this.config.logLevel ?? LogLevel.info] ); if (filteredLogs.length === 0) { return; } if (this.config.axiom instanceof Axiom) { this.config.axiom.ingest(this.config.dataset, filteredLogs); } else if (this.config.axiom instanceof AxiomWithoutBatching) { this.promises.push(this.config.axiom.ingest(this.config.dataset, filteredLogs)); } } async flush() { if (this.config.axiom instanceof Axiom) { await this.config.axiom.flush(); } else { await Promise.allSettled(this.promises); } this.promises = []; } } export { AxiomJSTransport }; //# sourceMappingURL=axiom-js.js.map