UNPKG

realm

Version:

Realm by MongoDB is an offline-first mobile database: an alternative to SQLite and key-value stores

82 lines 3.6 kB
"use strict"; //////////////////////////////////////////////////////////////////////////// // // Copyright 2023 Realm Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////// Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultLoggerLevel = exports.defaultLogger = exports.fromBindingLoggerLevelToLogLevel = exports.fromBindingLoggerLevelToNumericLogLevel = exports.toBindingLoggerLevel = exports.NumericLogLevel = void 0; const internal_1 = require("./internal"); var NumericLogLevel; (function (NumericLogLevel) { NumericLogLevel[NumericLogLevel["All"] = 0] = "All"; NumericLogLevel[NumericLogLevel["Trace"] = 1] = "Trace"; NumericLogLevel[NumericLogLevel["Debug"] = 2] = "Debug"; NumericLogLevel[NumericLogLevel["Detail"] = 3] = "Detail"; NumericLogLevel[NumericLogLevel["Info"] = 4] = "Info"; NumericLogLevel[NumericLogLevel["Warn"] = 5] = "Warn"; NumericLogLevel[NumericLogLevel["Error"] = 6] = "Error"; NumericLogLevel[NumericLogLevel["Fatal"] = 7] = "Fatal"; NumericLogLevel[NumericLogLevel["Off"] = 8] = "Off"; })(NumericLogLevel = exports.NumericLogLevel || (exports.NumericLogLevel = {})); /** @internal */ function toBindingLoggerLevel(arg) { const bindingLogLevel = inverseTranslationTable[arg]; (0, internal_1.assert)(bindingLogLevel !== undefined, `Unexpected log level: ${arg}`); return bindingLogLevel; } exports.toBindingLoggerLevel = toBindingLoggerLevel; /** @internal */ function fromBindingLoggerLevelToNumericLogLevel(arg) { // For now, these map 1-to-1 return arg; } exports.fromBindingLoggerLevelToNumericLogLevel = fromBindingLoggerLevelToNumericLogLevel; const translationTable = { [0 /* binding.LoggerLevel.All */]: "all", [1 /* binding.LoggerLevel.Trace */]: "trace", [2 /* binding.LoggerLevel.Debug */]: "debug", [3 /* binding.LoggerLevel.Detail */]: "detail", [4 /* binding.LoggerLevel.Info */]: "info", [5 /* binding.LoggerLevel.Warn */]: "warn", [6 /* binding.LoggerLevel.Error */]: "error", [7 /* binding.LoggerLevel.Fatal */]: "fatal", [8 /* binding.LoggerLevel.Off */]: "off", }; const inverseTranslationTable = Object.fromEntries(Object.entries(translationTable).map(([key, val]) => [val, Number(key)])); /** @internal */ function fromBindingLoggerLevelToLogLevel(arg) { return translationTable[arg]; } exports.fromBindingLoggerLevelToLogLevel = fromBindingLoggerLevelToLogLevel; /** @internal */ const defaultLogger = function (logLevel, message) { const formattedLogMessage = `[${logLevel}] ${message}`; /* eslint-disable no-console */ if (logLevel === "error" || logLevel === "fatal") { console.error(formattedLogMessage); } else if (logLevel === "warn") { console.warn(formattedLogMessage); } else { console.log(formattedLogMessage); } /* eslint-enable no-console */ }; exports.defaultLogger = defaultLogger; /** @internal */ exports.defaultLoggerLevel = "warn"; //# sourceMappingURL=Logger.js.map