diff --git a/CHANGELOG.md b/CHANGELOG.md index 56b45d5725..5873ff8519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * Improved performance of RQL queries on a non-linked string property using `>`, `>=`, `<`, `<=` operators and fixed behavior that a null string should be evaluated as less than everything, previously nulls were not matched. ([realm/realm-core#3939](https://github.com/realm/realm-core/issues/3939)) * Added support for using aggregate operations on Mixed properties in queries. ([realm/realm-core#7398](https://github.com/realm/realm-core/pull/7398)) * Improved file compaction performance on platforms with page sizes greater than 4k (for example arm64 Apple platforms) for files less than 256 pages in size. ([realm/realm-core#7492](https://github.com/realm/realm-core/pull/7492)) +* Added the ability to set the log level for one or more categories via `Realm.setLogLevel`. ([#6560](https://github.com/realm/realm-js/issues/6560)) ### Fixed * Aligned Dictionaries to Lists and Sets when they get cleared. ([#6205](https://github.com/realm/realm-core/issues/6205), since v10.3.0-rc.1) diff --git a/packages/realm/src/Logger.ts b/packages/realm/src/Logger.ts index 48b09632ba..aa90a88352 100644 --- a/packages/realm/src/Logger.ts +++ b/packages/realm/src/Logger.ts @@ -139,22 +139,6 @@ export const LOG_CATEGORIES = [ */ export type LogCategory = (typeof LOG_CATEGORIES)[number]; -/** - * Log options to use when setting the log level. - */ -export type LogOptions = { - /** - * The log level to be used by the logger. - * @default "info" - */ - level: LogLevel; - /** - * The category to set the log level for. If omitted, the log level - * is set for all categories (`"Realm"`). - */ - category?: LogCategory; -}; - /** * A callback passed to `Realm.App.Sync.setLogger` when instrumenting the Atlas Device Sync client with a custom logger. * @param level - The level of the log entry between 0 and 8 inclusively. diff --git a/packages/realm/src/Realm.ts b/packages/realm/src/Realm.ts index b0d047247e..81c55c4b45 100644 --- a/packages/realm/src/Realm.ts +++ b/packages/realm/src/Realm.ts @@ -32,7 +32,6 @@ import { List, LogCategory, LogLevel, - LogOptions, LoggerCallback, LoggerCallback1, LoggerCallback2, @@ -112,36 +111,18 @@ export class Realm { private static internals = new Set>(); /** - * Sets the log level across all levels. + * Sets the log level. * @param level - The log level to be used by the logger. The default value is `info`. + * @param category - The category to set the log level for. If omitted, the log level is set for all categories (`"Realm"`). * @note The log level can be changed during the lifetime of the application. * @since 12.0.0 * @example * Realm.setLogLevel("all"); */ - static setLogLevel(level: LogLevel): void; - - /** - * Sets the log level for a specific category. - * @param options - The log options to use. - * @note The log level can be changed during the lifetime of the application. - * @since 12.7.0 - * @example - * Realm.setLogLevel({ category: "Realm", level: "all" }); - */ - static setLogLevel(options: LogOptions): void; - static setLogLevel(arg: LogLevel | LogOptions) { - const setLevel = (level: LogLevel, category = "Realm") => { - assert(LOG_CATEGORIES.includes(category as LogCategory), `Unexpected log category: '${category}'`); - const categoryRef = binding.LogCategoryRef.getCategory(category); - categoryRef.setDefaultLevelThreshold(toBindingLoggerLevel(level)); - }; - - if (typeof arg === "string") { - setLevel(arg); - } else { - setLevel(arg.level, arg.category); - } + static setLogLevel(level: LogLevel, category: LogCategory = "Realm"): void { + assert(LOG_CATEGORIES.includes(category as LogCategory), `Unexpected log category: '${category}'`); + const categoryRef = binding.LogCategoryRef.getCategory(category); + categoryRef.setDefaultLevelThreshold(toBindingLoggerLevel(level)); } /**