Skip to content

Commit 23cedde

Browse files
author
sakshamg1304
committed
fix: support for timeout in settings, ansi color disable
1 parent 1469760 commit 23cedde

File tree

8 files changed

+73
-100
lines changed

8 files changed

+73
-100
lines changed

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.17.0] - 2026-01-09
9+
10+
### Added
11+
12+
- Added support for configurable ANSI color output in logging. ANSI colors in logging are now only applied when `isAnsiColorEnabled` is set to `true` in the logger configuration.
13+
14+
Example:
15+
16+
```php
17+
$vwoClient = VWO::init([
18+
'accountId' => '123456',
19+
'sdkKey' => '32-alpha-numeric-sdk-key',
20+
'logger' => [
21+
'level' => 'DEBUG',
22+
'isAnsiColorEnabled' => true, // Enable colored log levels in terminal
23+
],
24+
]);
25+
```
26+
27+
- Added support for configurable settings expiry and network timeout through `settingsConfig` option. The SDK now allows customization of settings cache expiration and network timeout for settings fetch requests.
28+
29+
Example:
30+
31+
```php
32+
$vwoClient = VWO::init([
33+
'accountId' => '123456',
34+
'sdkKey' => '32-alpha-numeric-sdk-key',
35+
'settingsConfig' => [
36+
'timeout' => 50000, // Network timeout for settings fetch in milliseconds (default: 50000)
37+
],
38+
]);
39+
```
840

941
## [1.16.0] - 2025-12-12
1042

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ To gain more control over VWO's logging behaviour, you can use the `logger` para
315315
| ------------- | -------------------------------------- | ------------ | -------- | --------------------- |
316316
| `level` | Log level to control verbosity of logs | Yes | string | `'DEBUG'` |
317317
| `prefix` | Custom prefix for log messages | No | string | `'CUSTOM LOG PREFIX'` |
318+
| `isAnsiColorEnabled` | Enable ANSI color codes for log levels in terminal output | No | boolean | `true` |
318319
| `transport` | Custom logger implementation | No | array | See example below |
319320

320321
#### Example 1: Set log level to control verbosity of logs
@@ -342,7 +343,22 @@ $vwoClient2 = VWO::init([
342343
]);
343344
```
344345

345-
#### Example 3: Implement custom transport to handle logs your way
346+
#### Example 3: Enable ANSI color codes for colored log levels in terminal
347+
348+
```php
349+
$vwoClient3 = VWO::init([
350+
'sdkKey' => '32-alpha-numeric-sdk-key',
351+
'accountId' => '123456',
352+
'logger' => [
353+
'level' => 'DEBUG',
354+
'isAnsiColorEnabled' => true, // Enable colored log levels (TRACE, DEBUG, INFO, WARN, ERROR)
355+
],
356+
]);
357+
```
358+
359+
Note: ANSI color codes are only applied when `isAnsiColorEnabled` is explicitly set to `true`. This prevents unwanted color codes in log files or non-terminal outputs. When disabled or not set, log levels are displayed as plain text.
360+
361+
#### Example 4: Implement custom transport to handle logs your way
346362

347363
The `transport` parameter allows you to implement custom logging behavior by providing your own logging functions. You can define handlers for different log levels (`debug`, `info`, `warn`, `error`, `trace`) to process log messages according to your needs.
348364

@@ -358,7 +374,7 @@ The transport object should implement handlers for the log levels you want to cu
358374

359375
For single transport you can use the `transport` parameter. For example:
360376
```php
361-
$vwoClient3 = VWO::init([
377+
$vwoClient4 = VWO::init([
362378
'sdkKey' => '32-alpha-numeric-sdk-key',
363379
'logger' => [
364380
'transport' => [
@@ -373,7 +389,7 @@ $vwoClient3 = VWO::init([
373389

374390
For multiple transports you can use the `transports` parameter. For example:
375391
```php
376-
$vwoClient3 = VWO::init([
392+
$vwoClient5 = VWO::init([
377393
'sdkKey' => '32-alpha-numeric-sdk-key',
378394
'logger' => [
379395
'transports' => [

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vwo/vwo-fme-php-sdk",
33

4-
"version": "1.16.0",
4+
"version": "1.17.0",
55
"keywords": ["vwo", "fme", "sdk"],
66
"license": "Apache-2.0",
77
"authors": [{

src/Constants/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Constants {
4040
const DEFAULT_EVENTS_PER_REQUEST = 100;
4141
const SDK_NAME = 'vwo-fme-php-sdk';
4242

43-
const SDK_VERSION = '1.16.0';
43+
const SDK_VERSION = '1.17.0';
4444
const AP = 'server';
4545

4646
const SETTINGS = 'settings';

src/Packages/Logger/LogMessageBuilder.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,20 @@ public function getFormattedLevel($level): string {
5656
'WHITE' => "\x1b[30m",
5757
'YELLOW' => "\x1b[33m"
5858
];
59-
60-
$logLevelColorInfoEnum = [
61-
LogLevelEnum::TRACE => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['WHITE']}{$upperCaseLevel}{$ansiColorEnum['RESET']}",
62-
LogLevelEnum::DEBUG => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['LIGHTBLUE']}{$upperCaseLevel} {$ansiColorEnum['RESET']}",
63-
LogLevelEnum::INFO => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['CYAN']}{$upperCaseLevel} {$ansiColorEnum['RESET']}",
64-
LogLevelEnum::WARN => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['YELLOW']}{$upperCaseLevel} {$ansiColorEnum['RESET']}",
65-
LogLevelEnum::ERROR => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['RED']}{$upperCaseLevel} {$ansiColorEnum['RESET']}"
66-
];
67-
68-
return $logLevelColorInfoEnum[$level] ?? "{$ansiColorEnum['BOLD']}{$ansiColorEnum['RED']}INVALID{$ansiColorEnum['RESET']}";
59+
// if loggerConfig.isAnsiColorEnabled is true, then use the formatted level, otherwise return the level as it is
60+
if(isset($this->loggerConfig['isAnsiColorEnabled']) && $this->loggerConfig['isAnsiColorEnabled']) {
61+
$logLevelColorInfoEnum = [
62+
LogLevelEnum::TRACE => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['WHITE']}{$upperCaseLevel}{$ansiColorEnum['RESET']}",
63+
LogLevelEnum::DEBUG => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['LIGHTBLUE']}{$upperCaseLevel} {$ansiColorEnum['RESET']}",
64+
LogLevelEnum::INFO => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['CYAN']}{$upperCaseLevel} {$ansiColorEnum['RESET']}",
65+
LogLevelEnum::WARN => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['YELLOW']}{$upperCaseLevel} {$ansiColorEnum['RESET']}",
66+
LogLevelEnum::ERROR => "{$ansiColorEnum['BOLD']}{$ansiColorEnum['RED']}{$upperCaseLevel} {$ansiColorEnum['RESET']}"
67+
];
68+
69+
return $logLevelColorInfoEnum[$level] ?? "{$ansiColorEnum['BOLD']}{$ansiColorEnum['RED']}INVALID{$ansiColorEnum['RESET']}";
70+
} else {
71+
return $upperCaseLevel;
72+
}
6973
}
7074

7175
public function getFormattedDateTime(): string {

src/Packages/NetworkLayer/Client/NetworkClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private function shouldUseCurl($networkOptions)
5959
return false;
6060
}
6161

62-
private function makeCurlRequest($url, $method, $headers, $body = null, $timeout = 5, $retryConfig = [])
62+
private function makeCurlRequest($url, $method, $headers, $body = null, $timeout = 5000, $retryConfig = [])
6363
{
6464
// Merge with defaults to ensure all keys are present
6565
$retryConfig = array_merge(Constants::DEFAULT_RETRY_CONFIG, $retryConfig);
@@ -81,7 +81,7 @@ private function makeCurlRequest($url, $method, $headers, $body = null, $timeout
8181
curl_setopt_array($ch, [
8282
CURLOPT_URL => $url,
8383
CURLOPT_RETURNTRANSFER => true,
84-
CURLOPT_TIMEOUT => $timeout,
84+
CURLOPT_TIMEOUT_MS => $timeout,
8585
CURLOPT_CUSTOMREQUEST => $method,
8686
CURLOPT_SSL_VERIFYPEER => false,
8787
CURLOPT_SSL_VERIFYHOST => false,
@@ -274,7 +274,7 @@ public function GET($request)
274274
'GET',
275275
$networkOptions['headers'],
276276
null,
277-
$networkOptions['timeout'] / 1000,
277+
$networkOptions['timeout'],
278278
$this->retryConfig
279279
);
280280
$rawResponse = $curlResponse['body'];
@@ -310,7 +310,7 @@ public function POST($request)
310310
'POST',
311311
$networkOptions['headers'],
312312
$networkOptions['body'],
313-
$networkOptions['timeout'] / 1000,
313+
$networkOptions['timeout'],
314314
$this->retryConfig
315315
);
316316

src/Services/SettingsService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function __construct($options, $logManager) {
5656
// Assigning values to properties
5757
$this->sdkKey = $options['sdkKey'];
5858
$this->accountId = $options['accountId'];
59-
$this->expiry = isset($options['settings']['expiry']) ? $options['settings']['expiry'] : Constants::SETTINGS_EXPIRY;
60-
$this->networkTimeout = isset($options['settings']['timeout']) ? $options['settings']['timeout'] : Constants::SETTINGS_TIMEOUT;
59+
$this->expiry = isset($options['settingsConfig']['expiry']) ? $options['settingsConfig']['expiry'] : Constants::SETTINGS_EXPIRY;
60+
$this->networkTimeout = isset($options['settingsConfig']['timeout']) ? $options['settingsConfig']['timeout'] : Constants::SETTINGS_TIMEOUT;
6161

6262
// Parsing URL if provided
6363
if (isset($options['gatewayService']['url'])) {

src/Utils/LogMessageBuilder.php

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)