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
88 changes: 88 additions & 0 deletions packages/sdk/browser/src/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { BasicLogger, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common';

import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions';
import { BrowserOptions as LDOptions } from './options';

// The exported LDIdentifyOptions and LDOptions are the browser specific implementations.
// These shadow the common implementations.
export type { LDIdentifyOptions, LDOptions };

export type {
AutoEnvAttributes,
BasicLogger,
BasicLoggerOptions,
EvaluationSeriesContext,
EvaluationSeriesData,
Hook,
HookMetadata,
IdentifySeriesContext,
IdentifySeriesData,
IdentifySeriesResult,
IdentifySeriesStatus,
LDContext,
LDContextCommon,
LDContextMeta,
LDEvaluationDetail,
LDEvaluationDetailTyped,
LDEvaluationReason,
LDFlagSet,
LDFlagValue,
LDTimeoutError,
LDInspection,
LDLogger,
LDLogLevel,
LDMultiKindContext,
LDSingleKindContext,
} from '@launchdarkly/js-client-sdk-common';

/**
* Provides a basic {@link LDLogger} implementation.
*
* This logging implementation uses a basic format that includes only the log level
* and the message text. By default this uses log level 'info' and the output is
* written to `console.error`.
*
* To use the logger created by this function, put it into {@link LDOptions.logger}. If
* you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger
* that will log "info" level and higher priorty messages and it will log messages to
* console.info, console.warn, and console.error.
*
* @param options Configuration for the logger. If no options are specified, the
* logger uses `{ level: 'info' }`.
*
* @example
* This example shows how to use `basicLogger` in your SDK options to enable console
* logging only at `warn` and `error` levels.
* ```javascript
* const ldOptions = {
* logger: basicLogger({ level: 'warn' }),
* };
* ```
*
* @example
* This example shows how to use `basicLogger` in your SDK options to cause all
* log output to go to `console.log`
* ```javascript
* const ldOptions = {
* logger: basicLogger({ destination: console.log }),
* };
* ```
*
* * @example
* The configuration also allows you to control the destination for each log level.
* ```javascript
* const ldOptions = {
* logger: basicLogger({
* destination: {
* debug: console.debug,
* info: console.info,
* warn: console.warn,
* error:console.error
* }
* }),
* };
* ```
*/
export function basicLogger(options: BasicLoggerOptions): LDLogger {
return new BasicLogger(options);
}
53 changes: 4 additions & 49 deletions packages/sdk/browser/src/compat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,13 @@
* Some code changes may still be required, for example {@link LDOptions} removes
* support for some previously available options.
*/
import {
basicLogger,
EvaluationSeriesContext,
EvaluationSeriesData,
Hook,
HookMetadata,
IdentifySeriesContext,
IdentifySeriesData,
IdentifySeriesResult,
IdentifySeriesStatus,
LDContext,
LDContextCommon,
LDContextMeta,
LDEvaluationDetail,
LDEvaluationDetailTyped,
LDEvaluationReason,
LDFlagSet,
LDIdentifyOptions,
LDLogger,
LDLogLevel,
LDMultiKindContext,
LDOptions,
LDSingleKindContext,
} from '..';
import { LDContext, LDOptions } from '@launchdarkly/js-client-sdk-common';

import { LDClient } from './LDClientCompat';
import LDClientCompatImpl from './LDClientCompatImpl';

export type {
LDClient,
LDFlagSet,
LDContext,
LDContextCommon,
LDContextMeta,
LDMultiKindContext,
LDSingleKindContext,
LDLogLevel,
LDLogger,
LDOptions,
LDEvaluationDetail,
LDEvaluationDetailTyped,
LDEvaluationReason,
LDIdentifyOptions,
Hook,
HookMetadata,
EvaluationSeriesContext,
EvaluationSeriesData,
IdentifySeriesContext,
IdentifySeriesData,
IdentifySeriesResult,
IdentifySeriesStatus,
basicLogger,
};
export * from '../common';
export type { LDClient };

/**
* Creates an instance of the LaunchDarkly client. This version of initialization is for
Expand Down
110 changes: 4 additions & 106 deletions packages/sdk/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,13 @@
*
* @packageDocumentation
*/
import {
AutoEnvAttributes,
BasicLogger,
BasicLoggerOptions,
EvaluationSeriesContext,
EvaluationSeriesData,
Hook,
HookMetadata,
IdentifySeriesContext,
IdentifySeriesData,
IdentifySeriesResult,
IdentifySeriesStatus,
LDContext,
LDContextCommon,
LDContextMeta,
LDEvaluationDetail,
LDEvaluationDetailTyped,
LDEvaluationReason,
LDFlagSet,
LDInspection,
LDLogger,
LDLogLevel,
LDMultiKindContext,
LDSingleKindContext,
} from '@launchdarkly/js-client-sdk-common';
import { AutoEnvAttributes } from '@launchdarkly/js-client-sdk-common';

// The exported LDClient and LDOptions are the browser specific implementations.
// These shadow the common implementations.
import { BrowserClient, LDClient } from './BrowserClient';
import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions';
import { BrowserOptions as LDOptions } from './options';
import { LDOptions } from './common';

export type {
LDClient,
LDFlagSet,
LDContext,
LDContextCommon,
LDContextMeta,
LDMultiKindContext,
LDSingleKindContext,
LDLogLevel,
LDLogger,
LDOptions,
LDEvaluationDetail,
LDEvaluationDetailTyped,
LDEvaluationReason,
LDIdentifyOptions,
Hook,
HookMetadata,
EvaluationSeriesContext,
EvaluationSeriesData,
IdentifySeriesContext,
IdentifySeriesData,
IdentifySeriesResult,
IdentifySeriesStatus,
LDInspection,
};
export * from './common';
export type { LDClient };

/**
* Creates an instance of the LaunchDarkly client.
Expand All @@ -88,55 +38,3 @@ export function initialize(clientSideId: string, options?: LDOptions): LDClient
// AutoEnvAttributes are not supported yet in the browser SDK.
return new BrowserClient(clientSideId, AutoEnvAttributes.Disabled, options);
}

/**
* Provides a basic {@link LDLogger} implementation.
*
* This logging implementation uses a basic format that includes only the log level
* and the message text. By default this uses log level 'info' and the output is
* written to `console.error`.
*
* To use the logger created by this function, put it into {@link LDOptions.logger}. If
* you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger
* that will log "info" level and higher priorty messages and it will log messages to
* console.info, console.warn, and console.error.
*
* @param options Configuration for the logger. If no options are specified, the
* logger uses `{ level: 'info' }`.
*
* @example
* This example shows how to use `basicLogger` in your SDK options to enable console
* logging only at `warn` and `error` levels.
* ```javascript
* const ldOptions = {
* logger: basicLogger({ level: 'warn' }),
* };
* ```
*
* @example
* This example shows how to use `basicLogger` in your SDK options to cause all
* log output to go to `console.log`
* ```javascript
* const ldOptions = {
* logger: basicLogger({ destination: console.log }),
* };
* ```
*
* * @example
* The configuration also allows you to control the destination for each log level.
* ```javascript
* const ldOptions = {
* logger: basicLogger({
* destination: {
* debug: console.debug,
* info: console.info,
* warn: console.warn,
* error:console.error
* }
* }),
* };
* ```
*/
export function basicLogger(options: BasicLoggerOptions): LDLogger {
return new BasicLogger(options);
}