Skip to content

Commit 1c411a1

Browse files
authored
feat: Add support for getting the logger from server-side SDKs. (#684)
1 parent 99a38ae commit 1c411a1

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

packages/shared/sdk-server/__tests__/LDClientImpl.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,17 @@ describe('LDClientImpl', () => {
259259
await client.waitForInitialization({ timeout: Number.MAX_SAFE_INTEGER });
260260
expect(logger.getCount(LogLevel.Warn)).toBe(0);
261261
});
262+
263+
it('provides access to the underlying logger', async () => {
264+
const logger = new TestLogger();
265+
client = createClient({ logger, offline: true });
266+
client.logger?.error('this is an error');
267+
expect(logger.getCount(LogLevel.Error)).toBe(1);
268+
logger.expectMessages([
269+
{
270+
level: LogLevel.Error,
271+
matches: /this is an error/,
272+
},
273+
]);
274+
});
262275
});

packages/shared/sdk-server/src/LDClientImpl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ export default class LDClientImpl implements LDClient {
128128

129129
private _hookRunner: HookRunner;
130130

131+
public get logger(): LDLogger | undefined {
132+
return this._logger;
133+
}
134+
131135
/**
132136
* Intended for use by platform specific client implementations.
133137
*

packages/shared/sdk-server/src/api/LDClient.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
LDEvaluationDetail,
44
LDEvaluationDetailTyped,
55
LDFlagValue,
6+
LDLogger,
67
} from '@launchdarkly/js-sdk-common';
78

89
import { LDMigrationOpEvent, LDMigrationVariation } from './data';
@@ -461,4 +462,11 @@ export interface LDClient {
461462
* @param Hook The hook to add.
462463
*/
463464
addHook?(hook: Hook): void;
465+
466+
/**
467+
* Get the logger used by this LDClient instance.
468+
*
469+
* For all platforms that support logging the logger should be present.
470+
*/
471+
get logger(): LDLogger | undefined;
464472
}

0 commit comments

Comments
 (0)