UNPKG

@forzalabs/remora

Version:

A powerful CLI tool for seamless data translation.

55 lines (54 loc) 2.67 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Affirm_1 = __importDefault(require("../Affirm")); class LoggerService { constructor() { this.outputs = []; this.register = (service) => __awaiter(this, void 0, void 0, function* () { (0, Affirm_1.default)(this.outputs, 'Unassigned outputs in logging service'); (0, Affirm_1.default)(service, 'Invalid service passed to logger.register'); (0, Affirm_1.default)(service.id, 'Invalid id used for registering new logging output service'); (0, Affirm_1.default)(!this.outputs.some(x => x.id === service.id), 'Trying to register logging output service that was already registered'); try { yield service.init(); this.outputs.push(service); } catch (error) { this.error(error); } }); this.isRegistered = (id) => { (0, Affirm_1.default)(this.outputs, 'Unassigned outputs in logging service'); (0, Affirm_1.default)(id, 'Invalid id used for checking if logging output service is registered'); return this.outputs.some(x => x.id === id); }; this.log = (text) => { this.outputs.forEach(x => x.log(text)); }; this.info = (text) => { this.outputs.forEach(x => x.info(text)); }; this.error = (error) => { if (error instanceof Error) this.outputs.forEach(x => x.error(error)); else if (typeof error === 'string') this.outputs.forEach(x => x.error(new Error(error))); else this.outputs.forEach(x => x.error(new Error(error))); }; } } const logger = new LoggerService(); exports.default = logger;