Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/shared/sdk-server/__tests__/LDClientImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/,
},
]);
});
});
4 changes: 4 additions & 0 deletions packages/shared/sdk-server/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
8 changes: 8 additions & 0 deletions packages/shared/sdk-server/src/api/LDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
LDEvaluationDetail,
LDEvaluationDetailTyped,
LDFlagValue,
LDLogger,
} from '@launchdarkly/js-sdk-common';

import { LDMigrationOpEvent, LDMigrationVariation } from './data';
Expand Down Expand Up @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an accessor here instead of a readonly property which should make this a little more flexible and also less likely to be assigned over in JS.

}