@@ -14,6 +14,7 @@ import {
1414 CompanyContext ,
1515 HookArgs ,
1616 InitOptions ,
17+ Logger ,
1718 RawFlag ,
1819 ReflagClient ,
1920 ReflagContext ,
@@ -152,6 +153,13 @@ export type ReflagPropsBase = {
152153 */
153154 initialLoading ?: boolean ;
154155
156+ /**
157+ * A custom logger to use for SDK logs.
158+ * Use this for advanced control or filtering of SDK logs.
159+ * If both `logger` and `debug` are provided, `logger` takes precedence.
160+ */
161+ logger ?: Logger ;
162+
155163 /**
156164 * Set to `true` to enable debug logging to the console,
157165 */
@@ -164,7 +172,7 @@ export type ReflagPropsBase = {
164172 */
165173export type ReflagInitOptionsBase = Omit <
166174 InitOptions ,
167- "user" | "company" | "other" | "otherContext" | "bootstrappedFlags"
175+ "user" | "company" | "other" | "otherContext" | "bootstrappedFlags" | "logger"
168176> ;
169177
170178/**
@@ -178,20 +186,28 @@ const reflagClients = new Map<string, ReflagClient>();
178186 * Only creates a new ReflagClient is not already created or if it hook is run on the server.
179187 * @internal
180188 */
181- function useReflagClient ( initOptions : InitOptions , debug = false ) {
189+ function useReflagClient ( initOptions : InitOptions & { debug ?: boolean } ) {
190+ const {
191+ debug = false ,
192+ logger,
193+ publishableKey,
194+ sdkVersion,
195+ ...clientOptions
196+ } = initOptions ;
182197 const isServer = typeof window === "undefined" ;
183- if ( isServer || ! reflagClients . has ( initOptions . publishableKey ) ) {
198+ if ( isServer || ! reflagClients . has ( publishableKey ) ) {
184199 const client = new ReflagClient ( {
185- ...initOptions ,
186- logger : debug ? console : undefined ,
187- sdkVersion : initOptions . sdkVersion ?? SDK_VERSION ,
200+ ...clientOptions ,
201+ publishableKey,
202+ logger : logger ?? ( debug ? console : undefined ) ,
203+ sdkVersion : sdkVersion ?? SDK_VERSION ,
188204 } ) ;
189205 if ( ! isServer ) {
190- reflagClients . set ( initOptions . publishableKey , client ) ;
206+ reflagClients . set ( publishableKey , client ) ;
191207 }
192208 return client ;
193209 }
194- return reflagClients . get ( initOptions . publishableKey ) ! ;
210+ return reflagClients . get ( publishableKey ) ! ;
195211}
196212
197213type ProviderContextType = {
@@ -204,7 +220,10 @@ const ProviderContext = createContext<ProviderContextType | null>(null);
204220/**
205221 * Props for the ReflagClientProvider.
206222 */
207- export type ReflagClientProviderProps = Omit < ReflagPropsBase , "debug" > & {
223+ export type ReflagClientProviderProps = Omit <
224+ ReflagPropsBase ,
225+ "debug" | "logger"
226+ > & {
208227 client : ReflagClient ;
209228} ;
210229
@@ -282,20 +301,20 @@ export function ReflagProvider({
282301 otherContext,
283302 loadingComponent,
284303 initialLoading = true ,
304+ logger,
285305 debug,
286306 ...config
287307} : ReflagProps ) {
288308 const resolvedContext = useMemo (
289309 ( ) => ( { user, company, other : otherContext , ...context } ) ,
290310 [ user , company , otherContext , context ] ,
291311 ) ;
292- const client = useReflagClient (
293- {
294- ...config ,
295- ...resolvedContext ,
296- } ,
312+ const client = useReflagClient ( {
313+ ...config ,
314+ ...resolvedContext ,
297315 debug,
298- ) ;
316+ logger,
317+ } ) ;
299318
300319 // Initialize the client if it is not already initialized
301320 useEffect ( ( ) => {
@@ -340,17 +359,17 @@ export function ReflagBootstrappedProvider({
340359 children,
341360 loadingComponent,
342361 initialLoading = false ,
362+ logger,
343363 debug,
344364 ...config
345365} : ReflagBootstrappedProps ) {
346- const client = useReflagClient (
347- {
348- ...config ,
349- ...flags . context ,
350- bootstrappedFlags : flags . flags ,
351- } ,
366+ const client = useReflagClient ( {
367+ ...config ,
368+ ...flags . context ,
369+ bootstrappedFlags : flags . flags ,
352370 debug,
353- ) ;
371+ logger,
372+ } ) ;
354373
355374 // Initialize the client if it is not already initialized
356375 useEffect ( ( ) => {
0 commit comments