@react-native-ohos/realm
Version:
Realm by MongoDB is an offline-first mobile database: an alternative to SQLite and key-value stores
155 lines • 5.57 kB
JavaScript
;
////////////////////////////////////////////////////////////////////////////
//
// 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.toBindingLogger = exports.LOG_CATEGORIES = exports.NumericLogLevel = void 0;
const binding_1 = require("./binding");
const assert_1 = require("./assert");
/**
* Log levels used by Realm
*/
var NumericLogLevel;
(function (NumericLogLevel) {
/**
* Same as 'Trace' but with even more output.
*/
NumericLogLevel[NumericLogLevel["All"] = 0] = "All";
/**
* A version of 'Debug' that allows for very high volume
* output.
*/
NumericLogLevel[NumericLogLevel["Trace"] = 1] = "Trace";
/**
* Reveal information that can aid debugging, no longer paying
* attention to efficiency.
*/
NumericLogLevel[NumericLogLevel["Debug"] = 2] = "Debug";
/**
* Same as 'Info', but prioritize completeness over minimalism.
*/
NumericLogLevel[NumericLogLevel["Detail"] = 3] = "Detail";
/**
* Reveal information about what is going on, but in a
* minimalistic fashion to avoid general overhead from logging
* and to keep volume down.
*/
NumericLogLevel[NumericLogLevel["Info"] = 4] = "Info";
/**
* Be silent unless when there is an error or a warning.
*/
NumericLogLevel[NumericLogLevel["Warn"] = 5] = "Warn";
/**
* Be silent unless when there is an error.
*/
NumericLogLevel[NumericLogLevel["Error"] = 6] = "Error";
/**
* Be silent unless when an error is fatal.
*/
NumericLogLevel[NumericLogLevel["Fatal"] = 7] = "Fatal";
/**
* Be silent.
*/
NumericLogLevel[NumericLogLevel["Off"] = 8] = "Off";
})(NumericLogLevel = exports.NumericLogLevel || (exports.NumericLogLevel = {}));
exports.LOG_CATEGORIES = [
"Realm",
"Realm.Storage",
"Realm.Storage.Transaction",
"Realm.Storage.Query",
"Realm.Storage.Object",
"Realm.Storage.Notification",
"Realm.Sync",
"Realm.Sync.Client",
"Realm.Sync.Client.Session",
"Realm.Sync.Client.Changeset",
"Realm.Sync.Client.Network",
"Realm.Sync.Client.Reset",
"Realm.Sync.Server",
"Realm.App",
"Realm.SDK",
];
/** @internal */
function toBindingLogger(logger) {
if (isLoggerWithLevel(logger)) {
return binding_1.binding.Helpers.makeLogger((_, level, message) => {
logger(fromBindingLoggerLevelToLogLevel(level), message);
});
}
else {
return binding_1.binding.Helpers.makeLogger((category, level, message) => {
logger({
category: category,
level: fromBindingLoggerLevelToLogLevel(level),
message,
});
});
}
}
exports.toBindingLogger = toBindingLogger;
function isLoggerWithLevel(logger) {
return logger.length === 2;
}
/** @internal */
function toBindingLoggerLevel(arg) {
const bindingLogLevel = inverseTranslationTable[arg];
(0, assert_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 ({ category, level, message }) {
const formattedLogMessage = `[${category} - ${level}] ${message}`;
/* eslint-disable no-console */
if (level === "error" || level === "fatal") {
console.error(formattedLogMessage);
}
else if (level === "warn") {
console.warn(formattedLogMessage);
}
else {
console.log(formattedLogMessage);
}
/* eslint-enable no-console */
};
exports.defaultLogger = defaultLogger;
/** @internal */
exports.defaultLoggerLevel = "warn";
//# sourceMappingURL=Logger.js.map