UNPKG

applicationinsights

Version:

Microsoft Application Insights module for Node.js

39 lines 1.67 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for details. Object.defineProperty(exports, "__esModule", { value: true }); exports.dispose = exports.enable = void 0; const api_logs_1 = require("@opentelemetry/api-logs"); const diagnostic_channel_1 = require("diagnostic-channel"); let logger; let logSendingLevel; const subscriber = (event) => { const severity = event.data.message.indexOf("Error:") > -1 ? api_logs_1.SeverityNumber.ERROR : (event.data.stderr ? api_logs_1.SeverityNumber.WARN : api_logs_1.SeverityNumber.INFO); if (logSendingLevel <= severity) { let message = event.data.message.toString(); // Message can have a trailing newline if (message.lastIndexOf("\n") === message.length - 1) { message = message.substring(0, message.length - 1); } const logRecord = { body: message, severityNumber: severity }; logger.emit(logRecord); } }; function enable(config) { if (config === null || config === void 0 ? void 0 : config.enabled) { logger = api_logs_1.logs.getLogger("ApplicationInsightsConsoleLogger"); logSendingLevel = config.logSendingLevel || api_logs_1.SeverityNumber.UNSPECIFIED; diagnostic_channel_1.channel.subscribe("console", subscriber, diagnostic_channel_1.trueFilter); } } exports.enable = enable; function dispose() { diagnostic_channel_1.channel.unsubscribe("console", subscriber); } exports.dispose = dispose; //# sourceMappingURL=console.sub.js.map