UNPKG

@vulcan-sql/core

Version:
48 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpLogger = void 0; const tslib_1 = require("tslib"); const logger_1 = require("../../models/extensions/logger"); const extensions_1 = require("../../models/extensions"); const axios_1 = require("axios"); const url_1 = require("../utils/url"); let HttpLogger = class HttpLogger extends logger_1.BaseActivityLogger { constructor() { super(...arguments); this.logger = this.getLogger(); } log(payload) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (!this.isEnabled()) return; const option = this.getOptions(); if (!(option === null || option === void 0 ? void 0 : option.connection)) { throw new Error('Http logger connection should be provided'); } const headers = option.connection.headers; const url = (0, url_1.getUrl)(option.connection); try { // get connection info from option and use axios to send a post requet to the endpoint yield this.sendActivityLog(url, payload, headers); this.logger.debug(`Activity log sent`); } catch (err) { this.logger.debug(`Failed to send activity log to http logger, url: ${url}`); throw err; } }); } sendActivityLog(url, payload, headers) { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield axios_1.default.post(url, payload, { headers: headers, }); }); } }; HttpLogger = tslib_1.__decorate([ (0, extensions_1.VulcanInternalExtension)('activity-log'), (0, extensions_1.VulcanExtensionId)(logger_1.ActivityLoggerType.HTTP_LOGGER) ], HttpLogger); exports.HttpLogger = HttpLogger; //# sourceMappingURL=httpLogger.js.map