Skip to content

Commit cf87023

Browse files
committed
up
1 parent f10db02 commit cf87023

17 files changed

+64
-60
lines changed

lib/core/audience_evaluator/index.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { getLogger } from '../../modules/logging';
17-
18-
import fns from '../../utils/fns';
16+
;
1917
import {
2018
LOG_LEVEL,
2119
} from '../../utils/enums';
@@ -25,11 +23,13 @@ import * as odpSegmentsConditionEvaluator from './odp_segment_condition_evaluato
2523
import { Audience, Condition, OptimizelyUserContext } from '../../shared_types';
2624
import { CONDITION_EVALUATOR_ERROR, UNKNOWN_CONDITION_TYPE } from '../../error_messages';
2725
import { AUDIENCE_EVALUATION_RESULT, EVALUATING_AUDIENCE} from '../../log_messages';
26+
import { LoggerFacade } from '../../logging/logger';
2827

29-
const logger = getLogger();
3028
const MODULE_NAME = 'AUDIENCE_EVALUATOR';
3129

3230
export class AudienceEvaluator {
31+
private logger?: LoggerFacade;
32+
3333
private typeToEvaluatorMap: {
3434
[key: string]: {
3535
[key: string]: (condition: Condition, user: OptimizelyUserContext) => boolean | null
@@ -43,7 +43,8 @@ export class AudienceEvaluator {
4343
* Optimizely evaluators cannot be overridden.
4444
* @constructor
4545
*/
46-
constructor(UNSTABLE_conditionEvaluators: unknown) {
46+
constructor(UNSTABLE_conditionEvaluators: unknown, logger?: LoggerFacade) {
47+
this.logger = logger;
4748
this.typeToEvaluatorMap = {
4849
...UNSTABLE_conditionEvaluators as any,
4950
custom_attribute: customAttributeConditionEvaluator,
@@ -77,16 +78,15 @@ export class AudienceEvaluator {
7778
const evaluateAudience = (audienceId: string) => {
7879
const audience = audiencesById[audienceId];
7980
if (audience) {
80-
logger.log(
81-
LOG_LEVEL.DEBUG,
82-
EVALUATING_AUDIENCE, MODULE_NAME, audienceId, JSON.stringify(audience.conditions)
81+
this.logger?.debug(
82+
EVALUATING_AUDIENCE, audienceId, JSON.stringify(audience.conditions)
8383
);
8484
const result = conditionTreeEvaluator.evaluate(
8585
audience.conditions as unknown[] ,
8686
this.evaluateConditionWithUserAttributes.bind(this, user)
8787
);
8888
const resultText = result === null ? 'UNKNOWN' : result.toString().toUpperCase();
89-
logger.log(LOG_LEVEL.DEBUG, AUDIENCE_EVALUATION_RESULT, MODULE_NAME, audienceId, resultText);
89+
this.logger?.debug(AUDIENCE_EVALUATION_RESULT, audienceId, resultText);
9090
return result;
9191
}
9292
return null;
@@ -105,15 +105,14 @@ export class AudienceEvaluator {
105105
evaluateConditionWithUserAttributes(user: OptimizelyUserContext, condition: Condition): boolean | null {
106106
const evaluator = this.typeToEvaluatorMap[condition.type];
107107
if (!evaluator) {
108-
logger.log(LOG_LEVEL.WARNING, UNKNOWN_CONDITION_TYPE, MODULE_NAME, JSON.stringify(condition));
108+
this.logger?.warn(UNKNOWN_CONDITION_TYPE, JSON.stringify(condition));
109109
return null;
110110
}
111111
try {
112112
return evaluator.evaluate(condition, user);
113113
} catch (err: any) {
114-
logger.log(
115-
LOG_LEVEL.ERROR,
116-
CONDITION_EVALUATOR_ERROR, MODULE_NAME, condition.type, err.message
114+
this.logger?.error(
115+
CONDITION_EVALUATOR_ERROR, condition.type, err.message
117116
);
118117
}
119118

@@ -123,6 +122,6 @@ export class AudienceEvaluator {
123122

124123
export default AudienceEvaluator;
125124

126-
export const createAudienceEvaluator = function(UNSTABLE_conditionEvaluators: unknown): AudienceEvaluator {
127-
return new AudienceEvaluator(UNSTABLE_conditionEvaluators);
125+
export const createAudienceEvaluator = function(UNSTABLE_conditionEvaluators: unknown, logger?: LoggerFacade): AudienceEvaluator {
126+
return new AudienceEvaluator(UNSTABLE_conditionEvaluators, logger);
128127
};

lib/core/decision_service/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ export class DecisionService {
142142
private userProfileService: UserProfileService | null;
143143

144144
constructor(options: DecisionServiceOptions) {
145-
this.audienceEvaluator = createAudienceEvaluator(options.UNSTABLE_conditionEvaluators);
146-
this.forcedVariationMap = {};
147145
this.logger = options.logger;
146+
this.audienceEvaluator = createAudienceEvaluator(options.UNSTABLE_conditionEvaluators, this.logger);
147+
this.forcedVariationMap = {};
148148
this.userProfileService = options.userProfileService || null;
149149
}
150150

lib/error_messages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
export const NOTIFICATION_LISTENER_EXCEPTION = 'Notification listener for (%s) threw exception: %s';
1717
export const BROWSER_ODP_MANAGER_INITIALIZATION_FAILED = '%s: Error initializing Browser ODP Manager.';
18-
export const CONDITION_EVALUATOR_ERROR = '%s: Error evaluating audience condition of type %s: %s';
18+
export const CONDITION_EVALUATOR_ERROR = 'Error evaluating audience condition of type %s: %s';
1919
export const DATAFILE_AND_SDK_KEY_MISSING =
2020
'%s: You must provide at least one of sdkKey or datafile. Cannot start Optimizely';
2121
export const EXPERIMENT_KEY_NOT_IN_DATAFILE = '%s: Experiment key %s is not in datafile.';
@@ -103,7 +103,7 @@ export const EVENT_ACTION_INVALID = 'Event action invalid.';
103103
export const FAILED_TO_SEND_ODP_EVENTS = 'failed to send odp events';
104104
export const UNABLE_TO_GET_VUID_VUID_MANAGER_NOT_AVAILABLE = 'Unable to get VUID - VuidManager is not available'
105105
export const UNKNOWN_CONDITION_TYPE =
106-
'%s: Audience condition %s has an unknown condition type. You may need to upgrade to a newer release of the Optimizely SDK.';
106+
'Audience condition %s has an unknown condition type. You may need to upgrade to a newer release of the Optimizely SDK.';
107107
export const UNKNOWN_MATCH_TYPE =
108108
'%s: Audience condition %s uses an unknown match type. You may need to upgrade to a newer release of the Optimizely SDK.';
109109
export const UNRECOGNIZED_DECIDE_OPTION = 'Unrecognized decide option %s provided.';

lib/event_processor/batch_event_processor.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { getMockLogger } from '../tests/mock/mock_logger';
2626
import { getMockRepeater } from '../tests/mock/mock_repeater';
2727
import * as retry from '../utils/executor/backoff_retry_runner';
2828
import { ServiceState, StartupLog } from '../service';
29-
import { LogLevel } from '../modules/logging';
29+
import { LogLevel } from '../logging/logger';
3030

3131
const getMockDispatcher = () => {
3232
return {
@@ -53,12 +53,12 @@ describe('QueueingEventProcessor', async () => {
5353
it('should log startupLogs on start', () => {
5454
const startupLogs: StartupLog[] = [
5555
{
56-
level: LogLevel.WARNING,
56+
level: LogLevel.Warn,
5757
message: 'warn message',
5858
params: [1, 2]
5959
},
6060
{
61-
level: LogLevel.ERROR,
61+
level: LogLevel.Error,
6262
message: 'error message',
6363
params: [3, 4]
6464
},
@@ -78,8 +78,8 @@ describe('QueueingEventProcessor', async () => {
7878

7979

8080
expect(logger.log).toHaveBeenCalledTimes(2);
81-
expect(logger.log).toHaveBeenNthCalledWith(1, LogLevel.WARNING, 'warn message', 1, 2);
82-
expect(logger.log).toHaveBeenNthCalledWith(2, LogLevel.ERROR, 'error message', 3, 4);
81+
expect(logger.log).toHaveBeenNthCalledWith(1, LogLevel.Warn, 'warn message', 1, 2);
82+
expect(logger.log).toHaveBeenNthCalledWith(2, LogLevel.Error, 'error message', 3, 4);
8383
});
8484

8585
it('should resolve onRunning() when start() is called', async () => {

lib/event_processor/batch_event_processor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Cache } from "../utils/cache/cache";
1919
import { EventDispatcher, EventDispatcherResponse, LogEvent } from "./event_dispatcher/event_dispatcher";
2020
import { buildLogEvent } from "./event_builder/log_event";
2121
import { BackoffController, ExponentialBackoff, IntervalRepeater, Repeater } from "../utils/repeater/repeater";
22-
import { LoggerFacade } from "../modules/logging";
22+
import { LoggerFacade } from '../logging/logger';
2323
import { BaseService, ServiceState, StartupLog } from "../service";
2424
import { Consumer, Fn, Producer } from "../utils/type";
2525
import { RunResult, runWithRetry } from "../utils/executor/backoff_retry_runner";

lib/event_processor/event_processor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
import { ConversionEvent, ImpressionEvent } from './event_builder/user_event'
1717
import { LogEvent } from './event_dispatcher/event_dispatcher'
18-
import { getLogger } from '../modules/logging'
1918
import { Service } from '../service'
2019
import { Consumer, Fn } from '../utils/type';
2120

lib/event_processor/event_processor_factory.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { DEFAULT_EVENT_BATCH_SIZE, DEFAULT_EVENT_FLUSH_INTERVAL, DEFAULT_MAX_BAC
1919
import { BatchEventProcessor, BatchEventProcessorConfig, EventWithId } from './batch_event_processor';
2020
import { ExponentialBackoff, IntervalRepeater } from '../utils/repeater/repeater';
2121
import { getMockSyncCache } from '../tests/mock/mock_cache';
22-
import { LogLevel } from '../modules/logging';
22+
import { LogLevel } from '../logging/logger';
2323

2424
vi.mock('./batch_event_processor');
2525
vi.mock('../utils/repeater/repeater');
@@ -160,7 +160,7 @@ describe('getBatchEventProcessor', () => {
160160

161161
const startupLogs = MockBatchEventProcessor.mock.calls[0][0].startupLogs;
162162
expect(startupLogs).toEqual(expect.arrayContaining([{
163-
level: LogLevel.WARNING,
163+
level: LogLevel.Warn,
164164
message: 'Invalid flushInterval %s, defaulting to %s',
165165
params: [undefined, DEFAULT_EVENT_FLUSH_INTERVAL],
166166
}]));
@@ -181,7 +181,7 @@ describe('getBatchEventProcessor', () => {
181181

182182
const startupLogs = MockBatchEventProcessor.mock.calls[0][0].startupLogs;
183183
expect(startupLogs).toEqual(expect.arrayContaining([{
184-
level: LogLevel.WARNING,
184+
level: LogLevel.Warn,
185185
message: 'Invalid flushInterval %s, defaulting to %s',
186186
params: [-1, DEFAULT_EVENT_FLUSH_INTERVAL],
187187
}]));
@@ -217,7 +217,7 @@ describe('getBatchEventProcessor', () => {
217217

218218
const startupLogs = MockBatchEventProcessor.mock.calls[0][0].startupLogs;
219219
expect(startupLogs).toEqual(expect.arrayContaining([{
220-
level: LogLevel.WARNING,
220+
level: LogLevel.Warn,
221221
message: 'Invalid batchSize %s, defaulting to %s',
222222
params: [undefined, DEFAULT_EVENT_BATCH_SIZE],
223223
}]));
@@ -236,7 +236,7 @@ describe('getBatchEventProcessor', () => {
236236

237237
const startupLogs = MockBatchEventProcessor.mock.calls[0][0].startupLogs;
238238
expect(startupLogs).toEqual(expect.arrayContaining([{
239-
level: LogLevel.WARNING,
239+
level: LogLevel.Warn,
240240
message: 'Invalid batchSize %s, defaulting to %s',
241241
params: [-1, DEFAULT_EVENT_BATCH_SIZE],
242242
}]));

lib/log_messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const VALID_USER_PROFILE_SERVICE = 'Valid user profile service provided.'
9090
export const VARIATION_REMOVED_FOR_USER = 'Variation mapped to experiment %s has been removed for user %s.';
9191

9292
export const VALID_BUCKETING_ID = 'BucketingId is valid: "%s"';
93-
export const EVALUATING_AUDIENCE = '%s: Starting to evaluate audience "%s" with conditions: %s.';
93+
export const EVALUATING_AUDIENCE = 'Starting to evaluate audience "%s" with conditions: %s.';
9494
export const EVALUATING_AUDIENCES_COMBINED = 'Evaluating audiences for %s "%s": %s.';
9595
export const AUDIENCE_EVALUATION_RESULT = '%s: Audience "%s" evaluated to %s.';
9696
export const AUDIENCE_EVALUATION_RESULT_COMBINED = 'Audiences for %s %s collectively evaluated to %s.';

lib/logging/logger_factory.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { LogLevel, LogResolver } from './logger';
1+
// import { LogLevel, LogResolver } from './logger';
22

3-
type LevelPreset = {
4-
level: LogLevel;
5-
resolver?: LogResolver;
6-
}
3+
// type LevelPreset = {
4+
// level: LogLevel;
5+
// resolver?: LogResolver;
6+
// }
77

8-
const levelPresetSymbol = Symbol('levelPreset');
8+
// const levelPresetSymbol = Symbol('levelPreset');
99

10-
export type OpaqueLevelPreset = {
11-
[levelPresetSymbol]: unknown;
12-
};
10+
// export type OpaqueLevelPreset = {
11+
// [levelPresetSymbol]: unknown;
12+
// };
1313

14-
const Info: LevelPreset = {
15-
level: LogLevel.Info,
16-
};
14+
// const Info: LevelPreset = {
15+
// level: LogLevel.Info,
16+
// };
1717

18-
export const InfoLog: OpaqueLevelPreset = {
19-
[levelPresetSymbol]: Info,
20-
};
18+
// export const InfoLog: OpaqueLevelPreset = {
19+
// [levelPresetSymbol]: Info,
20+
// };

lib/odp/odp_manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { v4 as uuidV4} from 'uuid';
18-
import { LoggerFacade } from '../modules/logging';
18+
import { LoggerFacade } from '../logging/logger';
1919

2020
import { OdpIntegrationConfig, odpIntegrationsAreEqual } from './odp_config';
2121
import { OdpEventManager } from './event_manager/odp_event_manager';

0 commit comments

Comments
 (0)