UNPKG

@itwin/presentation-frontend

Version:

Frontend of iModel.js Presentation library

66 lines 2.5 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Core */ Object.defineProperty(exports, "__esModule", { value: true }); exports.consoleDiagnosticsHandler = consoleDiagnosticsHandler; exports.createCombinedDiagnosticsHandler = createCombinedDiagnosticsHandler; const presentation_common_1 = require("@itwin/presentation-common"); /** * A function which logs messages to the console. * @public */ function consoleDiagnosticsHandler(diagnostics) { // eslint-disable-next-line no-console diagnostics.backendVersion && console.log(`Backend version: ${diagnostics.backendVersion}`); diagnostics.logs && handleDiagnosticLogs(diagnostics.logs, (msg, stack) => { /* note: we're duplicating the message if it's logged at both editor and dev severity levels */ const str = buildLogMessageString(msg, stack); if (msg.severity.editor) { getConsoleLogFunc(msg.severity.editor)(str); } if (msg.severity.dev) { getConsoleLogFunc(msg.severity.dev)(str); } }); } /** * A function which calls all diagnostics handlers passed to it. * @public */ function createCombinedDiagnosticsHandler(handlers) { return (diagnostics) => { handlers.forEach((handler) => handler(diagnostics)); }; } function handleDiagnosticLogs(logs, messageHandler, stack = []) { logs.forEach((log) => { if (presentation_common_1.DiagnosticsLogEntry.isMessage(log)) { messageHandler(log, stack); } else if (log.logs) { handleDiagnosticLogs(log.logs, messageHandler, [...stack, log]); } }); } function buildLogMessageString(msg, _stack) { return msg.message; } function getConsoleLogFunc(severity) { switch (severity) { case "error": return console.error; // eslint-disable-line no-console case "warning": return console.warn; // eslint-disable-line no-console case "info": case "debug": case "trace": return console.log; // eslint-disable-line no-console } } //# sourceMappingURL=Diagnostics.js.map