diff --git a/packages/shared/sdk-server/__tests__/LDClientImpl.test.ts b/packages/shared/sdk-server/__tests__/LDClientImpl.test.ts index 34d97823d..8cd437241 100644 --- a/packages/shared/sdk-server/__tests__/LDClientImpl.test.ts +++ b/packages/shared/sdk-server/__tests__/LDClientImpl.test.ts @@ -259,4 +259,17 @@ describe('LDClientImpl', () => { await client.waitForInitialization({ timeout: Number.MAX_SAFE_INTEGER }); expect(logger.getCount(LogLevel.Warn)).toBe(0); }); + + it('provides access to the underlying logger', async () => { + const logger = new TestLogger(); + client = createClient({ logger, offline: true }); + client.logger?.error('this is an error'); + expect(logger.getCount(LogLevel.Error)).toBe(1); + logger.expectMessages([ + { + level: LogLevel.Error, + matches: /this is an error/, + }, + ]); + }); }); diff --git a/packages/shared/sdk-server/src/LDClientImpl.ts b/packages/shared/sdk-server/src/LDClientImpl.ts index bdc4df775..08a25dba2 100644 --- a/packages/shared/sdk-server/src/LDClientImpl.ts +++ b/packages/shared/sdk-server/src/LDClientImpl.ts @@ -128,6 +128,10 @@ export default class LDClientImpl implements LDClient { private _hookRunner: HookRunner; + public get logger(): LDLogger | undefined { + return this._logger; + } + /** * Intended for use by platform specific client implementations. * diff --git a/packages/shared/sdk-server/src/api/LDClient.ts b/packages/shared/sdk-server/src/api/LDClient.ts index 221d762f8..0d6d1d7c2 100644 --- a/packages/shared/sdk-server/src/api/LDClient.ts +++ b/packages/shared/sdk-server/src/api/LDClient.ts @@ -3,6 +3,7 @@ import { LDEvaluationDetail, LDEvaluationDetailTyped, LDFlagValue, + LDLogger, } from '@launchdarkly/js-sdk-common'; import { LDMigrationOpEvent, LDMigrationVariation } from './data'; @@ -461,4 +462,11 @@ export interface LDClient { * @param Hook The hook to add. */ addHook?(hook: Hook): void; + + /** + * Get the logger used by this LDClient instance. + * + * For all platforms that support logging the logger should be present. + */ + get logger(): LDLogger | undefined; }