@@ -48,6 +48,12 @@ import LocalStorageBackedNamedEventQueue from './events/local-storage-backed-nam
48
48
import { IClientConfig , IPrecomputedClientConfig } from './i-client-config' ;
49
49
import { sdkName , sdkVersion } from './sdk-data' ;
50
50
51
+ /**
52
+ * Valid log levels for the Eppo SDK logger.
53
+ * @public
54
+ */
55
+ export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent' ;
56
+
51
57
/**
52
58
* Configuration interface for synchronous client initialization.
53
59
* @public
@@ -424,12 +430,12 @@ export class EppoJSClient extends EppoClient {
424
430
425
431
return ConfigLoaderStatus . COMPLETED ;
426
432
} )
427
- . catch ( ( e ) => {
433
+ . catch ( ( err ) => {
428
434
applicationLogger . warn (
435
+ { err } ,
429
436
'Eppo SDK encountered an error initializing from the configuration store' ,
430
- e ,
431
437
) ;
432
- initFromConfigStoreError = e ;
438
+ initFromConfigStoreError = err ;
433
439
return ConfigLoaderStatus . FAILED ;
434
440
} )
435
441
. then ( ( status ) => {
@@ -457,10 +463,13 @@ export class EppoJSClient extends EppoClient {
457
463
return ConfigLoaderStatus . DID_NOT_PRODUCE ;
458
464
}
459
465
} )
460
- . catch ( ( e ) => {
461
- applicationLogger . warn ( 'Eppo SDK encountered an error initializing from fetching' , e ) ;
466
+ . catch ( ( err ) => {
467
+ applicationLogger . warn (
468
+ { err } ,
469
+ 'Eppo SDK encountered an error initializing from fetching' ,
470
+ ) ;
462
471
// eslint-disable-next-line @typescript-eslint/no-unused-vars
463
- initFromFetchError = e ;
472
+ initFromFetchError = err ;
464
473
return ConfigLoaderStatus . FAILED ;
465
474
} )
466
475
. then ( ( status ) => {
@@ -501,7 +510,7 @@ export class EppoJSClient extends EppoClient {
501
510
? initFromConfigStoreError
502
511
: new Error ( 'Eppo SDK: No configuration source produced a valid configuration' ) ;
503
512
}
504
- applicationLogger . debug ( ' Initialization source' , initializationSource ) ;
513
+ applicationLogger . debug ( ` Initialization source: ${ initializationSource } ` ) ;
505
514
} catch ( error : unknown ) {
506
515
initializationError = error instanceof Error ? error : new Error ( String ( error ) ) ;
507
516
}
@@ -544,7 +553,10 @@ export class EppoJSClient extends EppoClient {
544
553
memoryOnlyConfigurationStore
545
554
. setEntries ( config . flagsConfiguration )
546
555
. catch ( ( err ) =>
547
- applicationLogger . warn ( 'Error setting flags for memory-only configuration store' , err ) ,
556
+ applicationLogger . warn (
557
+ { err } ,
558
+ 'Error setting flags for memory-only configuration store' ,
559
+ ) ,
548
560
) ;
549
561
this . setFlagConfigurationStore ( memoryOnlyConfigurationStore ) ;
550
562
@@ -591,12 +603,13 @@ export class EppoJSClient extends EppoClient {
591
603
forceMemoryOnly : true ,
592
604
} ) ;
593
605
this . useCustomAssignmentCache ( assignmentCache ) ;
594
- } catch ( error ) {
606
+ } catch ( err ) {
595
607
applicationLogger . warn (
608
+ { err } ,
596
609
'Eppo SDK encountered an error initializing, assignment calls will return the default value and not be logged' ,
597
610
) ;
598
611
if ( throwOnFailedInitialization ) {
599
- throw error ;
612
+ throw err ;
600
613
}
601
614
}
602
615
@@ -893,12 +906,12 @@ export function offlinePrecomputedInit(
893
906
try {
894
907
configurationWire = JSON . parse ( config . precomputedConfiguration ) ;
895
908
if ( ! configurationWire . precomputed ) throw new Error ( ) ;
896
- } catch ( error ) {
909
+ } catch ( err ) {
897
910
const errorMessage = 'Invalid precomputed configuration wire' ;
898
911
if ( throwOnFailedInitialization ) {
899
912
throw new Error ( errorMessage ) ;
900
913
}
901
- applicationLogger . error ( `[Eppo SDK] ${ errorMessage } ` ) ;
914
+ applicationLogger . error ( { err } , `[Eppo SDK] ${ errorMessage } ` ) ;
902
915
return EppoPrecomputedJSClient . instance ;
903
916
}
904
917
const { subjectKey, subjectAttributes, response } = configurationWire . precomputed ;
@@ -909,15 +922,18 @@ export function offlinePrecomputedInit(
909
922
memoryOnlyPrecomputedStore
910
923
. setEntries ( parsedResponse . flags )
911
924
. catch ( ( err ) =>
912
- applicationLogger . warn ( 'Error setting precomputed assignments for memory-only store' , err ) ,
925
+ applicationLogger . warn (
926
+ { err } ,
927
+ 'Error setting precomputed assignments for memory-only store' ,
928
+ ) ,
913
929
) ;
914
930
memoryOnlyPrecomputedStore . salt = parsedResponse . salt ;
915
931
916
932
const memoryOnlyPrecomputedBanditStore = precomputedBanditStoreFactory ( ) ;
917
933
memoryOnlyPrecomputedBanditStore
918
934
. setEntries ( parsedResponse . bandits )
919
935
. catch ( ( err ) =>
920
- applicationLogger . warn ( 'Error setting precomputed bandits for memory-only store' , err ) ,
936
+ applicationLogger . warn ( { err } , 'Error setting precomputed bandits for memory-only store' ) ,
921
937
) ;
922
938
memoryOnlyPrecomputedBanditStore . salt = parsedResponse . salt ;
923
939
@@ -963,12 +979,13 @@ export function offlinePrecomputedInit(
963
979
EppoPrecomputedJSClient . instance . setBanditLogger ( config . banditLogger ) ;
964
980
}
965
981
EppoPrecomputedJSClient . instance . useCustomAssignmentCache ( assignmentCache ) ;
966
- } catch ( error ) {
982
+ } catch ( err ) {
967
983
applicationLogger . warn (
984
+ { err } ,
968
985
'[Eppo SDK] Encountered an error initializing precomputed client, assignment calls will return the default value and not be logged' ,
969
986
) ;
970
987
if ( throwOnFailedInitialization ) {
971
- throw error ;
988
+ throw err ;
972
989
}
973
990
}
974
991
@@ -994,6 +1011,25 @@ export function getPrecomputedInstance(): EppoPrecomputedClient {
994
1011
return EppoPrecomputedJSClient . instance ;
995
1012
}
996
1013
1014
+ /**
1015
+ * Sets the log level for the Eppo SDK logger globally.
1016
+ * This affects all logging across the entire SDK, including both
1017
+ * EppoJSClient and EppoPrecomputedJSClient instances.
1018
+ *
1019
+ * @param level - The log level to set:
1020
+ * - 'trace': Most verbose, logs everything
1021
+ * - 'debug': Detailed debugging information
1022
+ * - 'info': General informational messages
1023
+ * - 'warn': Warning messages (default in production)
1024
+ * - 'error': Error messages only
1025
+ * - 'silent': Disable all logging
1026
+ *
1027
+ * @public
1028
+ */
1029
+ export function setLogLevel ( level : LogLevel ) : void {
1030
+ applicationLogger . level = level ;
1031
+ }
1032
+
997
1033
function newEventDispatcher (
998
1034
sdkKey : string ,
999
1035
config : IClientConfig [ 'eventTracking' ] = { } ,
0 commit comments