Skip to content

Commit 45e7ed8

Browse files
committed
break up log messages
1 parent 5481ce4 commit 45e7ed8

File tree

5 files changed

+63
-15
lines changed

5 files changed

+63
-15
lines changed

src/Optimizely/Enums/AudienceEvaluationLogs.php renamed to src/Optimizely/Enums/CommonAudienceEvaluationLogs.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
namespace Optimizely\Enums;
1919

20-
class AudienceEvaluationLogs
20+
class CommonAudienceEvaluationLogs
2121
{
2222
const AUDIENCE_EVALUATION_RESULT = "Audience \"%s\" evaluated to %s.";
23-
const AUDIENCE_EVALUATION_RESULT_COMBINED = "Audiences for %s collectively evaluated to %s.";
24-
const EVALUATING_AUDIENCES_COMBINED = "Evaluating audiences for %s: %s.";
2523
const EVALUATING_AUDIENCE = "Starting to evaluate audience \"%s\" with conditions: %s.";
2624
const INFINITE_ATTRIBUTE_VALUE = "Audience condition %s evaluated to UNKNOWN because the number value for user attribute \"%s\" is not in the range [-2^53, +2^53].";
2725
const MISSING_ATTRIBUTE_VALUE = "Audience condition %s evaluated to UNKNOWN because no value was passed for user attribute \"%s\".";
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright 2020, Optimizely
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Optimizely\Enums;
19+
20+
class ExperimentAudienceEvaluationLogs extends CommonAudienceEvaluationLogs
21+
{
22+
const AUDIENCE_EVALUATION_RESULT_COMBINED = "Audiences for experiment \"%s\" collectively evaluated to %s.";
23+
const EVALUATING_AUDIENCES_COMBINED = "Evaluating audiences for experiment \"%s\": %s.";
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright 2020, Optimizely
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Optimizely\Enums;
19+
20+
class RolloutAudienceEvaluationLogs extends CommonAudienceEvaluationLogs
21+
{
22+
const AUDIENCE_EVALUATION_RESULT_COMBINED = "Audiences for rule %s collectively evaluated to %s.";
23+
const EVALUATING_AUDIENCES_COMBINED = "Evaluating audiences for rule %s: %s.";
24+
}

src/Optimizely/Utils/CustomAttributeConditionEvaluator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2018-2019, Optimizely
3+
* Copyright 2018-2020, Optimizely
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818
namespace Optimizely\Utils;
1919

2020
use Monolog\Logger;
21-
use Optimizely\Enums\AudienceEvaluationLogs as logs;
21+
use Optimizely\Enums\CommonAudienceEvaluationLogs as logs;
2222
use Optimizely\Utils\Validator;
2323

2424
class CustomAttributeConditionEvaluator

src/Optimizely/Utils/Validator.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
use Monolog\Logger;
2121
use Optimizely\Config\ProjectConfigInterface;
2222
use Optimizely\Entity\Experiment;
23-
use Optimizely\Enums\AudienceEvaluationLogs;
23+
use Optimizely\Enums\ExperimentAudienceEvaluationLogs;
24+
use Optimizely\Enums\RolloutAudienceEvaluationLogs;
2425
use Optimizely\Logger\LoggerInterface;
2526
use Optimizely\Utils\ConditionTreeEvaluator;
2627
use Optimizely\Utils\CustomAttributeConditionEvaluator;
@@ -143,11 +144,12 @@ public static function areEventTagsValid($eventTags)
143144
*/
144145
public static function doesUserMeetAudienceConditions($config, $experiment, $userAttributes, $logger, $isRollout = null, $rolloutRule = null)
145146
{
146-
147-
$loggingStr = "experiment \"{$experiment->getKey()}\"";
147+
$loggingClass = 'Optimizely\Enums\ExperimentAudienceEvaluationLogs';
148+
$loggingStr = $experiment->getKey();
148149

149150
if ($isRollout) {
150-
$loggingStr = "rule {$rolloutRule}";
151+
$loggingClass = 'Optimizely\Enums\RolloutAudienceEvaluationLogs';
152+
$loggingStr = $rolloutRule;
151153
}
152154

153155
$audienceConditions = $experiment->getAudienceConditions();
@@ -156,15 +158,15 @@ public static function doesUserMeetAudienceConditions($config, $experiment, $use
156158
}
157159

158160
$logger->log(Logger::DEBUG, sprintf(
159-
AudienceEvaluationLogs::EVALUATING_AUDIENCES_COMBINED,
161+
$loggingClass::EVALUATING_AUDIENCES_COMBINED,
160162
$loggingStr,
161163
json_encode($audienceConditions)
162164
));
163165

164166
// Return true if experiment is not targeted to any audience.
165167
if (empty($audienceConditions)) {
166168
$logger->log(Logger::INFO, sprintf(
167-
AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT_COMBINED,
169+
$loggingClass::AUDIENCE_EVALUATION_RESULT_COMBINED,
168170
$loggingStr,
169171
'TRUE'
170172
));
@@ -180,14 +182,14 @@ public static function doesUserMeetAudienceConditions($config, $experiment, $use
180182
return $customAttrCondEval->evaluate($leafCondition);
181183
};
182184

183-
$evaluateAudience = function ($audienceId) use ($config, $evaluateCustomAttr, $logger) {
185+
$evaluateAudience = function ($audienceId) use ($config, $evaluateCustomAttr, $logger, $loggingClass) {
184186
$audience = $config->getAudience($audienceId);
185187
if ($audience === null) {
186188
return null;
187189
}
188190

189191
$logger->log(Logger::DEBUG, sprintf(
190-
AudienceEvaluationLogs::EVALUATING_AUDIENCE,
192+
$loggingClass::EVALUATING_AUDIENCE,
191193
$audienceId,
192194
json_encode($audience->getConditionsList())
193195
));
@@ -197,7 +199,7 @@ public static function doesUserMeetAudienceConditions($config, $experiment, $use
197199
$resultStr = $result === null ? 'UNKNOWN' : strtoupper(var_export($result, true));
198200

199201
$logger->log(Logger::DEBUG, sprintf(
200-
AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT,
202+
$loggingClass::AUDIENCE_EVALUATION_RESULT,
201203
$audienceId,
202204
$resultStr
203205
));
@@ -210,7 +212,7 @@ public static function doesUserMeetAudienceConditions($config, $experiment, $use
210212
$evalResult = $evalResult || false;
211213

212214
$logger->log(Logger::INFO, sprintf(
213-
AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT_COMBINED,
215+
$loggingClass::AUDIENCE_EVALUATION_RESULT_COMBINED,
214216
$loggingStr,
215217
strtoupper(var_export($evalResult, true))
216218
));

0 commit comments

Comments
 (0)