Skip to content

Commit

Permalink
feat: Add support for getting the logger from server-side SDKs.
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion committed Nov 13, 2024
1 parent 99a38ae commit 0451b25
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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;
}

0 comments on commit 0451b25

Please sign in to comment.