|
12 | 12 | */ |
13 | 13 | import { |
14 | 14 | AutoEnvAttributes, |
| 15 | + BasicLogger, |
| 16 | + BasicLoggerOptions, |
15 | 17 | EvaluationSeriesContext, |
16 | 18 | EvaluationSeriesData, |
17 | 19 | Hook, |
@@ -84,3 +86,54 @@ export function initialize(clientSideId: string, options?: LDOptions): LDClient |
84 | 86 | // AutoEnvAttributes are not supported yet in the browser SDK. |
85 | 87 | return new BrowserClient(clientSideId, AutoEnvAttributes.Disabled, options); |
86 | 88 | } |
| 89 | + |
| 90 | +/** |
| 91 | + * Provides a simple {@link LDLogger} implementation. |
| 92 | + * |
| 93 | + * This logging implementation uses a simple format that includes only the log level |
| 94 | + * and the message text. By default the output is written to `console.error`. |
| 95 | + * |
| 96 | + * To use the logger created by this function, put it into {@link LDOptions.logger}. If |
| 97 | + * you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger |
| 98 | + * that will log "info" level and higher priorty messages and it will log messages to |
| 99 | + * console.info, console.warn, and console.error. |
| 100 | + * |
| 101 | + * @param options Configuration for the logger. If no options are specified, the |
| 102 | + * logger uses `{ level: 'info' }`. |
| 103 | + * |
| 104 | + * @example |
| 105 | + * This example shows how to use `basicLogger` in your SDK options to enable console |
| 106 | + * logging only at `warn` and `error` levels. |
| 107 | + * ```javascript |
| 108 | + * const ldOptions = { |
| 109 | + * logger: basicLogger({ level: 'warn' }), |
| 110 | + * }; |
| 111 | + * ``` |
| 112 | + * |
| 113 | + * @example |
| 114 | + * This example shows how to use `basicLogger` in your SDK options to cause all |
| 115 | + * log output to go to `console.log` |
| 116 | + * ```javascript |
| 117 | + * const ldOptions = { |
| 118 | + * logger: ld.basicLogger({ destination: console.log }), |
| 119 | + * }; |
| 120 | + * ``` |
| 121 | + * |
| 122 | + * * @example |
| 123 | + * The configuration also allows you to control the destination for each log level. |
| 124 | + * ```javascript |
| 125 | + * const ldOptions = { |
| 126 | + * logger: ld.basicLogger({ |
| 127 | + * destination: { |
| 128 | + * debug: console.debug, |
| 129 | + * info: console.info, |
| 130 | + * warn: console.warn, |
| 131 | + * error:console.error |
| 132 | + * } |
| 133 | + * }), |
| 134 | + * }; |
| 135 | + * ``` |
| 136 | + */ |
| 137 | +export function basicLogger(options: BasicLoggerOptions): LDLogger { |
| 138 | + return new BasicLogger(options); |
| 139 | +} |
0 commit comments