19
19
*/
20
20
import { sprintf } from '../../utils/fns' ;
21
21
import murmurhash from 'murmurhash' ;
22
- import { LogHandler } from '../../modules/ logging' ;
22
+ import { LoggerFacade } from '../../logging/logger ' ;
23
23
import {
24
24
DecisionResponse ,
25
25
BucketerParams ,
@@ -30,11 +30,11 @@ import {
30
30
import { LOG_LEVEL } from '../../utils/enums' ;
31
31
import { INVALID_BUCKETING_ID , INVALID_GROUP_ID } from '../../error_messages' ;
32
32
33
- export const USER_NOT_IN_ANY_EXPERIMENT = '%s: User %s is not in any experiment of group %s.' ;
34
- export const USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP = '%s: User %s is not in experiment %s of group %s.' ;
35
- export const USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP = '%s: User %s is in experiment %s of group %s.' ;
36
- export const USER_ASSIGNED_TO_EXPERIMENT_BUCKET = '%s: Assigned bucket %s to user with bucketing ID %s.' ;
37
- export const INVALID_VARIATION_ID = '%s: Bucketed into an invalid variation ID. Returning null.' ;
33
+ export const USER_NOT_IN_ANY_EXPERIMENT = 'User %s is not in any experiment of group %s.' ;
34
+ export const USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP = 'User %s is not in experiment %s of group %s.' ;
35
+ export const USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP = 'User %s is in experiment %s of group %s.' ;
36
+ export const USER_ASSIGNED_TO_EXPERIMENT_BUCKET = 'Assigned bucket %s to user with bucketing ID %s.' ;
37
+ export const INVALID_VARIATION_ID = 'Bucketed into an invalid variation ID. Returning null.' ;
38
38
39
39
const HASH_SEED = 1 ;
40
40
const MAX_HASH_VALUE = Math . pow ( 2 , 32 ) ;
@@ -78,8 +78,7 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
78
78
79
79
// Return if user is not bucketed into any experiment
80
80
if ( bucketedExperimentId === null ) {
81
- bucketerParams . logger . log (
82
- LOG_LEVEL . INFO ,
81
+ bucketerParams . logger ?. info (
83
82
USER_NOT_IN_ANY_EXPERIMENT ,
84
83
MODULE_NAME ,
85
84
bucketerParams . userId ,
@@ -99,10 +98,8 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
99
98
100
99
// Return if user is bucketed into a different experiment than the one specified
101
100
if ( bucketedExperimentId !== bucketerParams . experimentId ) {
102
- bucketerParams . logger . log (
103
- LOG_LEVEL . INFO ,
101
+ bucketerParams . logger ?. info (
104
102
USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP ,
105
- MODULE_NAME ,
106
103
bucketerParams . userId ,
107
104
bucketerParams . experimentKey ,
108
105
groupId ,
@@ -121,10 +118,8 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
121
118
}
122
119
123
120
// Continue bucketing if user is bucketed into specified experiment
124
- bucketerParams . logger . log (
125
- LOG_LEVEL . INFO ,
121
+ bucketerParams . logger ?. info (
126
122
USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP ,
127
- MODULE_NAME ,
128
123
bucketerParams . userId ,
129
124
bucketerParams . experimentKey ,
130
125
groupId ,
@@ -141,10 +136,8 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
141
136
const bucketingId = `${ bucketerParams . bucketingId } ${ bucketerParams . experimentId } ` ;
142
137
const bucketValue = _generateBucketValue ( bucketingId ) ;
143
138
144
- bucketerParams . logger . log (
145
- LOG_LEVEL . DEBUG ,
139
+ bucketerParams . logger ?. debug (
146
140
USER_ASSIGNED_TO_EXPERIMENT_BUCKET ,
147
- MODULE_NAME ,
148
141
bucketValue ,
149
142
bucketerParams . userId ,
150
143
) ;
@@ -159,7 +152,7 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
159
152
if ( entityId !== null ) {
160
153
if ( ! bucketerParams . variationIdMap [ entityId ] ) {
161
154
if ( entityId ) {
162
- bucketerParams . logger . log ( LOG_LEVEL . WARNING , INVALID_VARIATION_ID , MODULE_NAME ) ;
155
+ bucketerParams . logger ?. warn ( INVALID_VARIATION_ID , MODULE_NAME ) ;
163
156
decideReasons . push ( [ INVALID_VARIATION_ID , MODULE_NAME ] ) ;
164
157
}
165
158
return {
@@ -180,21 +173,19 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
180
173
* @param {Group } group Group that experiment is in
181
174
* @param {string } bucketingId Bucketing ID
182
175
* @param {string } userId ID of user to be bucketed into experiment
183
- * @param {LogHandler } logger Logger implementation
176
+ * @param {LoggerFacade } logger Logger implementation
184
177
* @return {string|null } ID of experiment if user is bucketed into experiment within the group, null otherwise
185
178
*/
186
179
export const bucketUserIntoExperiment = function (
187
180
group : Group ,
188
181
bucketingId : string ,
189
182
userId : string ,
190
- logger : LogHandler
183
+ logger ?: LoggerFacade
191
184
) : string | null {
192
185
const bucketingKey = `${ bucketingId } ${ group . id } ` ;
193
186
const bucketValue = _generateBucketValue ( bucketingKey ) ;
194
- logger . log (
195
- LOG_LEVEL . DEBUG ,
187
+ logger ?. debug (
196
188
USER_ASSIGNED_TO_EXPERIMENT_BUCKET ,
197
- MODULE_NAME ,
198
189
bucketValue ,
199
190
userId ,
200
191
) ;
0 commit comments