Skip to content

Commit 791aa25

Browse files
Merge pull request #306 from splitio/SDKS_8273_reuse_matchers_debug_logs
[SDKS-8273] Reuse and polish debug logs
2 parents a3cdad8 + d8f8e1b commit 791aa25

27 files changed

+49
-147
lines changed

src/evaluator/matchers/all.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import { ENGINE_MATCHER_ALL } from '../../logger/constants';
2-
import { ILogger } from '../../logger/types';
1+
export function allMatcherContext() {
32

4-
export function allMatcherContext(log: ILogger) {
53
return function allMatcher(runtimeAttr: string): boolean {
6-
log.debug(ENGINE_MATCHER_ALL);
7-
84
return runtimeAttr != null;
95
};
106
}

src/evaluator/matchers/between.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { IBetweenMatcherData } from '../../dtos/types';
2-
import { ENGINE_MATCHER_BETWEEN } from '../../logger/constants';
3-
import { ILogger } from '../../logger/types';
42

5-
export function betweenMatcherContext(log: ILogger, ruleVO: IBetweenMatcherData) {
6-
return function betweenMatcher(runtimeAttr: number): boolean {
7-
8-
let isBetween = runtimeAttr >= ruleVO.start && runtimeAttr <= ruleVO.end;
3+
export function betweenMatcherContext(ruleVO: IBetweenMatcherData) {
94

10-
log.debug(ENGINE_MATCHER_BETWEEN, [runtimeAttr, ruleVO.start, ruleVO.end, isBetween]);
5+
return function betweenMatcher(runtimeAttr: number): boolean {
6+
const isBetween = runtimeAttr >= ruleVO.start && runtimeAttr <= ruleVO.end;
117

128
return isBetween;
139
};

src/evaluator/matchers/boolean.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { ENGINE_MATCHER_BOOLEAN } from '../../logger/constants';
2-
import { ILogger } from '../../logger/types';
1+
export function booleanMatcherContext(ruleAttr: boolean) {
32

4-
export function booleanMatcherContext(log: ILogger, ruleAttr: boolean) {
53
return function booleanMatcher(runtimeAttr: boolean): boolean {
6-
let booleanMatches = ruleAttr === runtimeAttr;
7-
8-
log.debug(ENGINE_MATCHER_BOOLEAN, [ruleAttr, runtimeAttr]);
4+
const booleanMatches = ruleAttr === runtimeAttr;
95

106
return booleanMatches;
117
};

src/evaluator/matchers/cont_all.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { ENGINE_MATCHER_CONTAINS_ALL } from '../../logger/constants';
2-
import { ILogger } from '../../logger/types';
31
import { findIndex } from '../../utils/lang';
42

5-
export function containsAllSetMatcherContext(log: ILogger, ruleAttr: string[]) {
3+
export function containsAllSetMatcherContext(ruleAttr: string[]) {
64
return function containsAllMatcher(runtimeAttr: string[]): boolean {
75
let containsAll = true;
86

@@ -15,8 +13,6 @@ export function containsAllSetMatcherContext(log: ILogger, ruleAttr: string[]) {
1513
}
1614
}
1715

18-
log.debug(ENGINE_MATCHER_CONTAINS_ALL, [runtimeAttr, ruleAttr, containsAll]);
19-
2016
return containsAll;
2117
};
2218
}

src/evaluator/matchers/cont_any.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import { ENGINE_MATCHER_CONTAINS_ANY } from '../../logger/constants';
2-
import { ILogger } from '../../logger/types';
31
import { findIndex } from '../../utils/lang';
42

5-
export function containsAnySetMatcherContext(log: ILogger, ruleAttr: string[]) {
3+
export function containsAnySetMatcherContext(ruleAttr: string[]) {
64
return function containsAnyMatcher(runtimeAttr: string[]): boolean {
75
let containsAny = false;
86

97
for (let i = 0; i < ruleAttr.length && !containsAny; i++) {
108
if (findIndex(runtimeAttr, e => e === ruleAttr[i]) >= 0) containsAny = true;
119
}
1210

13-
log.debug(ENGINE_MATCHER_CONTAINS_ANY, [runtimeAttr, ruleAttr, containsAny]);
14-
1511
return containsAny;
1612
};
1713
}

src/evaluator/matchers/cont_str.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { isString } from '../../utils/lang';
2-
import { ILogger } from '../../logger/types';
3-
import { ENGINE_MATCHER_CONTAINS_STRING } from '../../logger/constants';
42

5-
export function containsStringMatcherContext(log: ILogger, ruleAttr: string[]) {
3+
export function containsStringMatcherContext(ruleAttr: string[]) {
64
return function containsStringMatcher(runtimeAttr: string): boolean {
7-
let contains = ruleAttr.some(e => isString(runtimeAttr) && runtimeAttr.indexOf(e) > -1);
8-
9-
log.debug(ENGINE_MATCHER_CONTAINS_STRING, [runtimeAttr, ruleAttr, contains]);
5+
const contains = ruleAttr.some(e => isString(runtimeAttr) && runtimeAttr.indexOf(e) > -1);
106

117
return contains;
128
};

src/evaluator/matchers/dependency.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { thenable } from '../../utils/promise/thenable';
55
import { IDependencyMatcherValue, IEvaluation, ISplitEvaluator } from '../types';
66
import { ENGINE_MATCHER_DEPENDENCY, ENGINE_MATCHER_DEPENDENCY_PRE } from '../../logger/constants';
77

8-
export function dependencyMatcherContext(log: ILogger, { split, treatments }: IDependencyMatcherData, storage: IStorageSync | IStorageAsync) {
8+
export function dependencyMatcherContext({ split, treatments }: IDependencyMatcherData, storage: IStorageSync | IStorageAsync, log: ILogger) {
99

1010
function checkTreatment(evaluation: IEvaluation, acceptableTreatments: string[], parentName: string) {
1111
let matches = false;

src/evaluator/matchers/eq.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { ENGINE_MATCHER_EQUAL } from '../../logger/constants';
2-
import { ILogger } from '../../logger/types';
1+
export function equalToMatcherContext(ruleAttr: number) {
32

4-
export function equalToMatcherContext(log: ILogger, ruleAttr: number) {
53
return function equalToMatcher(runtimeAttr: number): boolean {
6-
let isEqual = runtimeAttr === ruleAttr;
7-
8-
log.debug(ENGINE_MATCHER_EQUAL, [runtimeAttr, ruleAttr, isEqual]);
4+
const isEqual = runtimeAttr === ruleAttr;
95

106
return isEqual;
117
};

src/evaluator/matchers/eq_set.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { ENGINE_MATCHER_EQUAL_TO_SET } from '../../logger/constants';
2-
import { ILogger } from '../../logger/types';
31
import { findIndex } from '../../utils/lang';
42

5-
export function equalToSetMatcherContext(log: ILogger, ruleAttr: string[]) {
3+
export function equalToSetMatcherContext(ruleAttr: string[]) {
64
return function equalToSetMatcher(runtimeAttr: string[]): boolean {
75
// Length being the same is the first condition.
86
let isEqual = runtimeAttr.length === ruleAttr.length;
@@ -12,8 +10,6 @@ export function equalToSetMatcherContext(log: ILogger, ruleAttr: string[]) {
1210
if (findIndex(ruleAttr, e => e === runtimeAttr[i]) < 0) isEqual = false;
1311
}
1412

15-
log.debug(ENGINE_MATCHER_EQUAL_TO_SET, [runtimeAttr, ruleAttr, isEqual]);
16-
1713
return isEqual;
1814
};
1915
}

src/evaluator/matchers/ew.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { ENGINE_MATCHER_ENDS_WITH } from '../../logger/constants';
2-
import { ILogger } from '../../logger/types';
31
import { endsWith } from '../../utils/lang';
42

5-
export function endsWithMatcherContext(log: ILogger, ruleAttr: string[]) {
3+
export function endsWithMatcherContext(ruleAttr: string[]) {
64
return function endsWithMatcher(runtimeAttr: string): boolean {
7-
let strEndsWith = ruleAttr.some(e => endsWith(runtimeAttr, e));
8-
9-
log.debug(ENGINE_MATCHER_ENDS_WITH, [runtimeAttr, ruleAttr, strEndsWith]);
5+
const strEndsWith = ruleAttr.some(e => endsWith(runtimeAttr, e));
106

117
return strEndsWith;
128
};

0 commit comments

Comments
 (0)