From 566e3ecac5cc72a3005f9b0c0867be49e84795eb Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 31 Oct 2022 09:22:32 +0100 Subject: [PATCH 01/15] feat(api): Optionally suppress warning about logger being overwritten --- api/src/api/diag.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index 3fd1027a62..8efcdcab66 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -67,7 +67,8 @@ export class DiagAPI implements DiagLogger { self.setLogger = ( logger: DiagLogger, - logLevel: DiagLogLevel = DiagLogLevel.INFO + logLevel: DiagLogLevel = DiagLogLevel.INFO, + suppressOverrideMessage = false ) => { if (logger === self) { // There isn't much we can do here. @@ -83,7 +84,7 @@ export class DiagAPI implements DiagLogger { const oldLogger = getGlobal('diag'); const newLogger = createLogLevelDiagLogger(logLevel, logger); // There already is an logger registered. We'll let it know before overwriting it. - if (oldLogger) { + if (oldLogger && !suppressOverrideMessage) { const stack = new Error().stack ?? ''; oldLogger.warn(`Current logger will be overwritten from ${stack}`); newLogger.warn( From 170458acc16ab7d57a787f6039b0e4424f832a93 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 31 Oct 2022 10:28:18 +0100 Subject: [PATCH 02/15] options bag --- api/src/api/diag.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index 8efcdcab66..084256177c 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -30,6 +30,10 @@ import { const API_NAME = 'diag'; +interface LoggerOptions { + suppressOverrideMessage?: boolean; +} + /** * Singleton object which represents the entry point to the OpenTelemetry internal * diagnostic API @@ -68,7 +72,7 @@ export class DiagAPI implements DiagLogger { self.setLogger = ( logger: DiagLogger, logLevel: DiagLogLevel = DiagLogLevel.INFO, - suppressOverrideMessage = false + options: LoggerOptions = {} ) => { if (logger === self) { // There isn't much we can do here. @@ -84,7 +88,7 @@ export class DiagAPI implements DiagLogger { const oldLogger = getGlobal('diag'); const newLogger = createLogLevelDiagLogger(logLevel, logger); // There already is an logger registered. We'll let it know before overwriting it. - if (oldLogger && !suppressOverrideMessage) { + if (oldLogger && !options.suppressOverrideMessage) { const stack = new Error().stack ?? ''; oldLogger.warn(`Current logger will be overwritten from ${stack}`); newLogger.warn( From c2b8ae2c7b24a90a0ff9c9c8d82b7a413c95bfa5 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 2 Nov 2022 09:45:41 +0100 Subject: [PATCH 03/15] update types --- api/src/api/diag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index 084256177c..a5a5a51033 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -122,7 +122,7 @@ export class DiagAPI implements DiagLogger { * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO. * @returns true if the logger was successfully registered, else false */ - public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel) => boolean; + public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel, options?: LoggerOptions) => boolean; /** * */ From f1d35299e82b24b5d776d624112d75988b831144 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 2 Nov 2022 09:46:52 +0100 Subject: [PATCH 04/15] changelog --- api/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/CHANGELOG.md b/api/CHANGELOG.md index 139f4a33fa..fb493e0772 100644 --- a/api/CHANGELOG.md +++ b/api/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## Unreleased + +* Optionally suppress warning about logger being overwritten ([#3366](https://www.github.com/open-telemetry/opentelemetry-js-api/pull/3366)) + ## [1.2.0](https://www.github.com/open-telemetry/opentelemetry-js-api/compare/v1.1.0...v1.2.0) (2022-08-09) ### Features From dc094f06f1043ead2d12d8b22bd951edf6f70291 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 2 Nov 2022 09:47:53 +0100 Subject: [PATCH 05/15] changelog heading --- api/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/CHANGELOG.md b/api/CHANGELOG.md index fb493e0772..ff82beb8e6 100644 --- a/api/CHANGELOG.md +++ b/api/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## Unreleased +### Features + * Optionally suppress warning about logger being overwritten ([#3366](https://www.github.com/open-telemetry/opentelemetry-js-api/pull/3366)) ## [1.2.0](https://www.github.com/open-telemetry/opentelemetry-js-api/compare/v1.1.0...v1.2.0) (2022-08-09) From f3c52a50041ccf3c539c74d36c56840ef087492a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 2 Nov 2022 09:52:17 +0100 Subject: [PATCH 06/15] document in api --- api/src/api/diag.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index a5a5a51033..6e343bacf8 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -120,6 +120,7 @@ export class DiagAPI implements DiagLogger { * * @param logger - [Optional] The DiagLogger instance to set as the default logger. * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO. + * @param options - [Optional] And object which can contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. * @returns true if the logger was successfully registered, else false */ public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel, options?: LoggerOptions) => boolean; From ea86043122515d0d8f08a76275ecebfa8c15b24e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 2 Nov 2022 11:52:05 +0100 Subject: [PATCH 07/15] overload --- api/src/api/diag.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index 6e343bacf8..b2c9fb6447 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -31,6 +31,7 @@ import { const API_NAME = 'diag'; interface LoggerOptions { + logLevel?: DiagLogLevel; suppressOverrideMessage?: boolean; } @@ -71,8 +72,7 @@ export class DiagAPI implements DiagLogger { self.setLogger = ( logger: DiagLogger, - logLevel: DiagLogLevel = DiagLogLevel.INFO, - options: LoggerOptions = {} + optionsOrLogLevel: DiagLogLevel | LoggerOptions = { logLevel: DiagLogLevel.INFO }, ) => { if (logger === self) { // There isn't much we can do here. @@ -85,10 +85,16 @@ export class DiagAPI implements DiagLogger { return false; } + if (typeof optionsOrLogLevel === 'number') { + optionsOrLogLevel = { + logLevel: optionsOrLogLevel, + } + } + const oldLogger = getGlobal('diag'); - const newLogger = createLogLevelDiagLogger(logLevel, logger); + const newLogger = createLogLevelDiagLogger(optionsOrLogLevel.logLevel ?? DiagLogLevel.INFO, logger); // There already is an logger registered. We'll let it know before overwriting it. - if (oldLogger && !options.suppressOverrideMessage) { + if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) { const stack = new Error().stack ?? ''; oldLogger.warn(`Current logger will be overwritten from ${stack}`); newLogger.warn( @@ -120,10 +126,18 @@ export class DiagAPI implements DiagLogger { * * @param logger - [Optional] The DiagLogger instance to set as the default logger. * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO. - * @param options - [Optional] And object which can contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. * @returns true if the logger was successfully registered, else false */ - public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel, options?: LoggerOptions) => boolean; + public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel) => boolean; + /** + * Set the global DiagLogger and DiagLogLevel. + * If a global diag logger is already set, this will override it. + * + * @param logger - [Optional] The DiagLogger instance to set as the default logger. + * @param options - [Optional] And object which can contain `logLevel: DiagLogLevel` used to filter logs sent to the logger. If not provided it will default to INFO. The object may also contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. + * @returns true if the logger was successfully registered, else false + */ + public setLogger!: (logger: DiagLogger, options?: LoggerOptions) => boolean; /** * */ From 50fed69b1260c7d6c5636fb2bafe534bcd9c304b Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 2 Nov 2022 11:56:26 +0100 Subject: [PATCH 08/15] move impl --- api/src/api/diag.ts | 70 +++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index b2c9fb6447..990d77c598 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -70,41 +70,6 @@ export class DiagAPI implements DiagLogger { // DiagAPI specific functions - self.setLogger = ( - logger: DiagLogger, - optionsOrLogLevel: DiagLogLevel | LoggerOptions = { logLevel: DiagLogLevel.INFO }, - ) => { - if (logger === self) { - // There isn't much we can do here. - // Logging to the console might break the user application. - // Try to log to self. If a logger was previously registered it will receive the log. - const err = new Error( - 'Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation' - ); - self.error(err.stack ?? err.message); - return false; - } - - if (typeof optionsOrLogLevel === 'number') { - optionsOrLogLevel = { - logLevel: optionsOrLogLevel, - } - } - - const oldLogger = getGlobal('diag'); - const newLogger = createLogLevelDiagLogger(optionsOrLogLevel.logLevel ?? DiagLogLevel.INFO, logger); - // There already is an logger registered. We'll let it know before overwriting it. - if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) { - const stack = new Error().stack ?? ''; - oldLogger.warn(`Current logger will be overwritten from ${stack}`); - newLogger.warn( - `Current logger will overwrite one already registered from ${stack}` - ); - } - - return registerGlobal('diag', newLogger, self, true); - }; - self.disable = () => { unregisterGlobal(API_NAME, self); }; @@ -128,7 +93,7 @@ export class DiagAPI implements DiagLogger { * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO. * @returns true if the logger was successfully registered, else false */ - public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel) => boolean; + public setLogger(logger: DiagLogger, logLevel?: DiagLogLevel): boolean; /** * Set the global DiagLogger and DiagLogLevel. * If a global diag logger is already set, this will override it. @@ -137,7 +102,38 @@ export class DiagAPI implements DiagLogger { * @param options - [Optional] And object which can contain `logLevel: DiagLogLevel` used to filter logs sent to the logger. If not provided it will default to INFO. The object may also contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. * @returns true if the logger was successfully registered, else false */ - public setLogger!: (logger: DiagLogger, options?: LoggerOptions) => boolean; + public setLogger(logger: DiagLogger, options?: LoggerOptions): boolean; + public setLogger(logger: DiagLogger, optionsOrLogLevel: DiagLogLevel | LoggerOptions = { logLevel: DiagLogLevel.INFO }) { + if (logger === this) { + // There isn't much we can do here. + // Logging to the console might break the user application. + // Try to log to self. If a logger was previously registered it will receive the log. + const err = new Error( + 'Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation' + ); + this.error(err.stack ?? err.message); + return false; + } + + if (typeof optionsOrLogLevel === 'number') { + optionsOrLogLevel = { + logLevel: optionsOrLogLevel, + } + } + + const oldLogger = getGlobal('diag'); + const newLogger = createLogLevelDiagLogger(optionsOrLogLevel.logLevel ?? DiagLogLevel.INFO, logger); + // There already is an logger registered. We'll let it know before overwriting it. + if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) { + const stack = new Error().stack ?? ''; + oldLogger.warn(`Current logger will be overwritten from ${stack}`); + newLogger.warn( + `Current logger will overwrite one already registered from ${stack}` + ); + } + + return registerGlobal('diag', newLogger, this, true); + } /** * */ From 0c4166650f468bf80a2709243adeff2fb2b58814 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 4 Nov 2022 18:59:31 +0100 Subject: [PATCH 09/15] Revert "move impl" This reverts commit 50fed69b1260c7d6c5636fb2bafe534bcd9c304b. --- api/src/api/diag.ts | 70 ++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index 990d77c598..b2c9fb6447 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -70,6 +70,41 @@ export class DiagAPI implements DiagLogger { // DiagAPI specific functions + self.setLogger = ( + logger: DiagLogger, + optionsOrLogLevel: DiagLogLevel | LoggerOptions = { logLevel: DiagLogLevel.INFO }, + ) => { + if (logger === self) { + // There isn't much we can do here. + // Logging to the console might break the user application. + // Try to log to self. If a logger was previously registered it will receive the log. + const err = new Error( + 'Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation' + ); + self.error(err.stack ?? err.message); + return false; + } + + if (typeof optionsOrLogLevel === 'number') { + optionsOrLogLevel = { + logLevel: optionsOrLogLevel, + } + } + + const oldLogger = getGlobal('diag'); + const newLogger = createLogLevelDiagLogger(optionsOrLogLevel.logLevel ?? DiagLogLevel.INFO, logger); + // There already is an logger registered. We'll let it know before overwriting it. + if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) { + const stack = new Error().stack ?? ''; + oldLogger.warn(`Current logger will be overwritten from ${stack}`); + newLogger.warn( + `Current logger will overwrite one already registered from ${stack}` + ); + } + + return registerGlobal('diag', newLogger, self, true); + }; + self.disable = () => { unregisterGlobal(API_NAME, self); }; @@ -93,7 +128,7 @@ export class DiagAPI implements DiagLogger { * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO. * @returns true if the logger was successfully registered, else false */ - public setLogger(logger: DiagLogger, logLevel?: DiagLogLevel): boolean; + public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel) => boolean; /** * Set the global DiagLogger and DiagLogLevel. * If a global diag logger is already set, this will override it. @@ -102,38 +137,7 @@ export class DiagAPI implements DiagLogger { * @param options - [Optional] And object which can contain `logLevel: DiagLogLevel` used to filter logs sent to the logger. If not provided it will default to INFO. The object may also contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. * @returns true if the logger was successfully registered, else false */ - public setLogger(logger: DiagLogger, options?: LoggerOptions): boolean; - public setLogger(logger: DiagLogger, optionsOrLogLevel: DiagLogLevel | LoggerOptions = { logLevel: DiagLogLevel.INFO }) { - if (logger === this) { - // There isn't much we can do here. - // Logging to the console might break the user application. - // Try to log to self. If a logger was previously registered it will receive the log. - const err = new Error( - 'Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation' - ); - this.error(err.stack ?? err.message); - return false; - } - - if (typeof optionsOrLogLevel === 'number') { - optionsOrLogLevel = { - logLevel: optionsOrLogLevel, - } - } - - const oldLogger = getGlobal('diag'); - const newLogger = createLogLevelDiagLogger(optionsOrLogLevel.logLevel ?? DiagLogLevel.INFO, logger); - // There already is an logger registered. We'll let it know before overwriting it. - if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) { - const stack = new Error().stack ?? ''; - oldLogger.warn(`Current logger will be overwritten from ${stack}`); - newLogger.warn( - `Current logger will overwrite one already registered from ${stack}` - ); - } - - return registerGlobal('diag', newLogger, this, true); - } + public setLogger!: (logger: DiagLogger, options?: LoggerOptions) => boolean; /** * */ From bb6df0a481f8e1616d7b8ae526f86fb473ccbc70 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 4 Nov 2022 19:01:39 +0100 Subject: [PATCH 10/15] no overload --- api/src/api/diag.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index b2c9fb6447..d872ab1162 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -72,7 +72,7 @@ export class DiagAPI implements DiagLogger { self.setLogger = ( logger: DiagLogger, - optionsOrLogLevel: DiagLogLevel | LoggerOptions = { logLevel: DiagLogLevel.INFO }, + optionsOrLogLevel: LoggerOptions | DiagLogLevel = { logLevel: DiagLogLevel.INFO }, ) => { if (logger === self) { // There isn't much we can do here. @@ -125,19 +125,10 @@ export class DiagAPI implements DiagLogger { * If a global diag logger is already set, this will override it. * * @param logger - [Optional] The DiagLogger instance to set as the default logger. - * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO. + * @param optionsOrLogLevel - [Optional] And object which can contain `logLevel: DiagLogLevel` used to filter logs sent to the logger. If not provided it will default to INFO. The object may also contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. Can also be just the `DiagLogLevel` for backwards compatibility. * @returns true if the logger was successfully registered, else false */ - public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel) => boolean; - /** - * Set the global DiagLogger and DiagLogLevel. - * If a global diag logger is already set, this will override it. - * - * @param logger - [Optional] The DiagLogger instance to set as the default logger. - * @param options - [Optional] And object which can contain `logLevel: DiagLogLevel` used to filter logs sent to the logger. If not provided it will default to INFO. The object may also contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. - * @returns true if the logger was successfully registered, else false - */ - public setLogger!: (logger: DiagLogger, options?: LoggerOptions) => boolean; + public setLogger!: (logger: DiagLogger, optionsOrLogLevel?: LoggerOptions | DiagLogLevel) => boolean; /** * */ From 2e37304f85aff9c34f1986b606600035d3c5da0c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 7 Nov 2022 08:38:59 +0100 Subject: [PATCH 11/15] lint --- api/src/api/diag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index d872ab1162..93fa2c0abe 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -88,7 +88,7 @@ export class DiagAPI implements DiagLogger { if (typeof optionsOrLogLevel === 'number') { optionsOrLogLevel = { logLevel: optionsOrLogLevel, - } + }; } const oldLogger = getGlobal('diag'); From 4a4628f7812ddc164d9f1b530efffeab0a341c16 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 7 Nov 2022 08:44:50 +0100 Subject: [PATCH 12/15] use interface to provide overload --- api/src/api/diag.ts | 26 ++++++++------------------ api/src/diag/types.ts | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/api/src/api/diag.ts b/api/src/api/diag.ts index 93fa2c0abe..516657d8c8 100644 --- a/api/src/api/diag.ts +++ b/api/src/api/diag.ts @@ -20,6 +20,7 @@ import { ComponentLoggerOptions, DiagLogFunction, DiagLogger, + DiagLoggerApi, DiagLogLevel, } from '../diag/types'; import { @@ -30,16 +31,11 @@ import { const API_NAME = 'diag'; -interface LoggerOptions { - logLevel?: DiagLogLevel; - suppressOverrideMessage?: boolean; -} - /** * Singleton object which represents the entry point to the OpenTelemetry internal * diagnostic API */ -export class DiagAPI implements DiagLogger { +export class DiagAPI implements DiagLogger, DiagLoggerApi { private static _instance?: DiagAPI; /** Get the singleton instance of the DiagAPI API */ @@ -70,9 +66,9 @@ export class DiagAPI implements DiagLogger { // DiagAPI specific functions - self.setLogger = ( - logger: DiagLogger, - optionsOrLogLevel: LoggerOptions | DiagLogLevel = { logLevel: DiagLogLevel.INFO }, + const setLogger: DiagLoggerApi['setLogger'] = ( + logger, + optionsOrLogLevel = { logLevel: DiagLogLevel.INFO }, ) => { if (logger === self) { // There isn't much we can do here. @@ -105,6 +101,8 @@ export class DiagAPI implements DiagLogger { return registerGlobal('diag', newLogger, self, true); }; + self.setLogger = setLogger; + self.disable = () => { unregisterGlobal(API_NAME, self); }; @@ -120,15 +118,7 @@ export class DiagAPI implements DiagLogger { self.error = _logProxy('error'); } - /** - * Set the global DiagLogger and DiagLogLevel. - * If a global diag logger is already set, this will override it. - * - * @param logger - [Optional] The DiagLogger instance to set as the default logger. - * @param optionsOrLogLevel - [Optional] And object which can contain `logLevel: DiagLogLevel` used to filter logs sent to the logger. If not provided it will default to INFO. The object may also contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. Can also be just the `DiagLogLevel` for backwards compatibility. - * @returns true if the logger was successfully registered, else false - */ - public setLogger!: (logger: DiagLogger, optionsOrLogLevel?: LoggerOptions | DiagLogLevel) => boolean; + public setLogger!: DiagLoggerApi['setLogger']; /** * */ diff --git a/api/src/diag/types.ts b/api/src/diag/types.ts index 54bf398d01..bdb4458cd1 100644 --- a/api/src/diag/types.ts +++ b/api/src/diag/types.ts @@ -96,3 +96,28 @@ export enum DiagLogLevel { export interface ComponentLoggerOptions { namespace: string; } + +export interface LoggerOptions { + logLevel?: DiagLogLevel; + suppressOverrideMessage?: boolean; +} + +export interface DiagLoggerApi { + /** + * Set the global DiagLogger and DiagLogLevel. + * If a global diag logger is already set, this will override it. + * + * @param logger - [Optional] The DiagLogger instance to set as the default logger. + * @param options - [Optional] And object which can contain `logLevel: DiagLogLevel` used to filter logs sent to the logger. If not provided it will default to INFO. The object may also contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. + * @returns true if the logger was successfully registered, else false + */ + setLogger(logger: DiagLogger, options?: LoggerOptions): boolean; + + /** + * + * @param logger - [Optional] The DiagLogger instance to set as the default logger. + * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO. + * @returns true if the logger was successfully registered, else false + */ + setLogger(logger: DiagLogger, logLevel?: DiagLogLevel): boolean; +} From 22fe3c4ef72781bf0a55fc439f4527cc2af1a0e2 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 8 Nov 2022 11:14:28 -0500 Subject: [PATCH 13/15] Update typedoc comments --- api/src/diag/types.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/api/src/diag/types.ts b/api/src/diag/types.ts index bdb4458cd1..e79e630f9b 100644 --- a/api/src/diag/types.ts +++ b/api/src/diag/types.ts @@ -98,7 +98,16 @@ export interface ComponentLoggerOptions { } export interface LoggerOptions { + /** + * The {@link DiagLogLevel} used to filter logs sent to the logger. + * + * @defaultValue DiagLogLevel.INFO + */ logLevel?: DiagLogLevel; + + /** + * Setting this value to `true` will suppress the warning message normally emitted when registering a logger when another logger is already registered. + */ suppressOverrideMessage?: boolean; } @@ -107,17 +116,17 @@ export interface DiagLoggerApi { * Set the global DiagLogger and DiagLogLevel. * If a global diag logger is already set, this will override it. * - * @param logger - [Optional] The DiagLogger instance to set as the default logger. - * @param options - [Optional] And object which can contain `logLevel: DiagLogLevel` used to filter logs sent to the logger. If not provided it will default to INFO. The object may also contain `suppressOverrideMessage: boolean` which will suppress the warning normally logged when a logger is already registered. - * @returns true if the logger was successfully registered, else false + * @param logger - [Optional] The {@link DiagLogger} instance to set as the default logger. + * @param options - [Optional] A {@link LoggerOptions} object. + * @returns `true` if the logger was successfully registered, else `false` */ setLogger(logger: DiagLogger, options?: LoggerOptions): boolean; /** * - * @param logger - [Optional] The DiagLogger instance to set as the default logger. - * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO. - * @returns true if the logger was successfully registered, else false + * @param logger - [Optional] The {@link DiagLogger} instance to set as the default logger. + * @param logLevel - [Optional] The {@link DiagLogLevel} used to filter logs sent to the logger. If not provided it will default to {@link DiagLogLevel.INFO}. + * @returns `true` if the logger was successfully registered, else `false` */ setLogger(logger: DiagLogger, logLevel?: DiagLogLevel): boolean; } From 56500bd18931759bdae59edb28dbca35591dcd73 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 8 Nov 2022 17:20:19 +0100 Subject: [PATCH 14/15] Update api/src/diag/types.ts --- api/src/diag/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/diag/types.ts b/api/src/diag/types.ts index e79e630f9b..1e64efa772 100644 --- a/api/src/diag/types.ts +++ b/api/src/diag/types.ts @@ -100,7 +100,7 @@ export interface ComponentLoggerOptions { export interface LoggerOptions { /** * The {@link DiagLogLevel} used to filter logs sent to the logger. - * + * * @defaultValue DiagLogLevel.INFO */ logLevel?: DiagLogLevel; From 455e948baf4dc03dca16bcd5241a9be17986a2d7 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 8 Nov 2022 13:49:33 -0500 Subject: [PATCH 15/15] Remove optional text --- api/src/diag/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/diag/types.ts b/api/src/diag/types.ts index 1e64efa772..e2ec879f03 100644 --- a/api/src/diag/types.ts +++ b/api/src/diag/types.ts @@ -116,16 +116,16 @@ export interface DiagLoggerApi { * Set the global DiagLogger and DiagLogLevel. * If a global diag logger is already set, this will override it. * - * @param logger - [Optional] The {@link DiagLogger} instance to set as the default logger. - * @param options - [Optional] A {@link LoggerOptions} object. + * @param logger - The {@link DiagLogger} instance to set as the default logger. + * @param options - A {@link LoggerOptions} object. If not provided, default values will be set. * @returns `true` if the logger was successfully registered, else `false` */ setLogger(logger: DiagLogger, options?: LoggerOptions): boolean; /** * - * @param logger - [Optional] The {@link DiagLogger} instance to set as the default logger. - * @param logLevel - [Optional] The {@link DiagLogLevel} used to filter logs sent to the logger. If not provided it will default to {@link DiagLogLevel.INFO}. + * @param logger - The {@link DiagLogger} instance to set as the default logger. + * @param logLevel - The {@link DiagLogLevel} used to filter logs sent to the logger. If not provided it will default to {@link DiagLogLevel.INFO}. * @returns `true` if the logger was successfully registered, else `false` */ setLogger(logger: DiagLogger, logLevel?: DiagLogLevel): boolean;