@splitsoftware/splitio-commons 2.6.0 → 2.6.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +3 -0
- package/cjs/listeners/browser.js +1 -0
- package/cjs/logger/constants.js +4 -3
- package/cjs/logger/index.js +37 -18
- package/cjs/logger/messages/info.js +1 -0
- package/cjs/logger/sdkLogger.js +7 -0
- package/cjs/storages/inMemory/EventsCacheInMemory.js +1 -0
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -0
- package/cjs/storages/inMemory/ImpressionsCacheInMemory.js +1 -0
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +1 -0
- package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +1 -0
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +1 -0
- package/cjs/sync/submitters/eventsSubmitter.js +2 -3
- package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionsSubmitter.js +2 -4
- package/cjs/sync/submitters/submitter.js +2 -1
- package/cjs/sync/submitters/telemetrySubmitter.js +3 -2
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +2 -3
- package/cjs/utils/settingsValidation/logger/builtinLogger.js +4 -3
- package/cjs/utils/settingsValidation/logger/commons.js +12 -15
- package/cjs/utils/settingsValidation/logger/pluggableLogger.js +9 -6
- package/esm/listeners/browser.js +2 -1
- package/esm/logger/constants.js +1 -0
- package/esm/logger/index.js +37 -18
- package/esm/logger/messages/info.js +1 -0
- package/esm/logger/sdkLogger.js +7 -0
- package/esm/storages/inMemory/EventsCacheInMemory.js +1 -0
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -0
- package/esm/storages/inMemory/ImpressionsCacheInMemory.js +1 -0
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +1 -0
- package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +1 -0
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +1 -0
- package/esm/sync/submitters/eventsSubmitter.js +2 -3
- package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionsSubmitter.js +2 -4
- package/esm/sync/submitters/submitter.js +2 -1
- package/esm/sync/submitters/telemetrySubmitter.js +3 -2
- package/esm/sync/submitters/uniqueKeysSubmitter.js +2 -3
- package/esm/utils/settingsValidation/logger/builtinLogger.js +4 -3
- package/esm/utils/settingsValidation/logger/commons.js +10 -14
- package/esm/utils/settingsValidation/logger/pluggableLogger.js +10 -7
- package/package.json +1 -1
- package/src/listeners/browser.ts +2 -1
- package/src/logger/constants.ts +1 -0
- package/src/logger/index.ts +36 -22
- package/src/logger/messages/info.ts +1 -0
- package/src/logger/sdkLogger.ts +7 -0
- package/src/logger/types.ts +4 -3
- package/src/storages/inMemory/EventsCacheInMemory.ts +1 -0
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +2 -0
- package/src/storages/inMemory/ImpressionsCacheInMemory.ts +1 -0
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +2 -0
- package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +3 -3
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +3 -3
- package/src/storages/types.ts +1 -0
- package/src/sync/submitters/eventsSubmitter.ts +2 -4
- package/src/sync/submitters/impressionCountsSubmitter.ts +1 -1
- package/src/sync/submitters/impressionsSubmitter.ts +2 -5
- package/src/sync/submitters/submitter.ts +1 -1
- package/src/sync/submitters/telemetrySubmitter.ts +3 -2
- package/src/sync/submitters/uniqueKeysSubmitter.ts +2 -3
- package/src/utils/settingsValidation/logger/builtinLogger.ts +5 -4
- package/src/utils/settingsValidation/logger/commons.ts +11 -11
- package/src/utils/settingsValidation/logger/pluggableLogger.ts +12 -8
- package/types/splitio.d.ts +26 -0
|
@@ -40,15 +40,16 @@ if (/^(enabled?|on)/i.test(initialState)) {
|
|
|
40
40
|
* @param settings - user config object, with an optional `debug` property of type boolean or string log level.
|
|
41
41
|
* @returns a logger instance with the log level at `settings.debug`. If `settings.debug` is invalid or not provided, `initialLogLevel` is used.
|
|
42
42
|
*/
|
|
43
|
-
export function validateLogger(settings: { debug: unknown }): ILogger {
|
|
44
|
-
const { debug } = settings;
|
|
43
|
+
export function validateLogger(settings: { debug: unknown, logger?: SplitIO.Logger }): ILogger {
|
|
44
|
+
const { debug, logger } = settings;
|
|
45
45
|
|
|
46
46
|
const logLevel: SplitIO.LogLevel | undefined = debug !== undefined ? getLogLevel(debug) : initialLogLevel;
|
|
47
47
|
|
|
48
48
|
const log = new Logger({ logLevel: logLevel || initialLogLevel }, allCodes);
|
|
49
|
+
log.setLogger(logger);
|
|
49
50
|
|
|
50
|
-
//
|
|
51
|
-
if (!logLevel) log._log(
|
|
51
|
+
// if logLevel is undefined at this point, it means that settings `debug` value is invalid
|
|
52
|
+
if (!logLevel) log._log('error', 'Invalid Log Level - No changes to the logs will be applied.');
|
|
52
53
|
|
|
53
54
|
return log;
|
|
54
55
|
}
|
|
@@ -10,15 +10,15 @@ import SplitIO from '../../../../types/splitio';
|
|
|
10
10
|
* @returns LogLevel of the given debugValue or undefined if the provided value is invalid
|
|
11
11
|
*/
|
|
12
12
|
export function getLogLevel(debugValue: unknown): SplitIO.LogLevel | undefined {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
return typeof debugValue === 'boolean' ?
|
|
14
|
+
debugValue ?
|
|
15
|
+
LogLevels.DEBUG :
|
|
16
|
+
LogLevels.NONE :
|
|
17
|
+
typeof debugValue === 'string' && isLogLevelString(debugValue) ?
|
|
18
|
+
debugValue :
|
|
19
|
+
undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isLogger(log: any): log is SplitIO.Logger {
|
|
23
|
+
return log !== null && typeof log === 'object' && typeof log.debug === 'function' && typeof log.info === 'function' && typeof log.warn === 'function' && typeof log.error === 'function';
|
|
24
24
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Logger, LogLevels } from '../../../logger';
|
|
2
2
|
import { ILogger } from '../../../logger/types';
|
|
3
3
|
import SplitIO from '../../../../types/splitio';
|
|
4
|
-
import { getLogLevel } from './commons';
|
|
4
|
+
import { getLogLevel, isLogger } from './commons';
|
|
5
5
|
|
|
6
|
-
function
|
|
7
|
-
return log
|
|
6
|
+
function isILogger(log: any): log is ILogger {
|
|
7
|
+
return isLogger(log) && typeof (log as any).setLogLevel === 'function';
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
// By default it starts disabled.
|
|
@@ -17,19 +17,23 @@ let initialLogLevel = LogLevels.NONE;
|
|
|
17
17
|
* @returns a logger instance, that might be: the provided logger at `settings.debug`, or one with the given `debug` log level,
|
|
18
18
|
* or one with NONE log level if `debug` is not defined or invalid.
|
|
19
19
|
*/
|
|
20
|
-
export function validateLogger(settings: { debug: unknown }): ILogger {
|
|
21
|
-
const { debug } = settings;
|
|
20
|
+
export function validateLogger(settings: { debug: unknown, logger?: SplitIO.Logger }): ILogger {
|
|
21
|
+
const { debug, logger } = settings;
|
|
22
22
|
let logLevel: SplitIO.LogLevel | undefined = initialLogLevel;
|
|
23
23
|
|
|
24
24
|
if (debug !== undefined) {
|
|
25
|
-
if (
|
|
25
|
+
if (isILogger(debug)) {
|
|
26
|
+
debug.setLogger(logger);
|
|
27
|
+
return debug;
|
|
28
|
+
}
|
|
26
29
|
logLevel = getLogLevel(settings.debug);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
const log = new Logger({ logLevel: logLevel || initialLogLevel });
|
|
33
|
+
log.setLogger(logger);
|
|
30
34
|
|
|
31
|
-
//
|
|
32
|
-
if (!logLevel) log._log(
|
|
35
|
+
// `debug` value is invalid if logLevel is undefined at this point
|
|
36
|
+
if (!logLevel) log._log('error', 'Invalid `debug` value at config. Logs will be disabled.');
|
|
33
37
|
|
|
34
38
|
return log;
|
|
35
39
|
}
|
package/types/splitio.d.ts
CHANGED
|
@@ -91,6 +91,10 @@ interface ISharedSettings {
|
|
|
91
91
|
* Do not change these settings unless you're working an advanced use case, like connecting to the Split proxy.
|
|
92
92
|
*/
|
|
93
93
|
urls?: SplitIO.UrlSettings;
|
|
94
|
+
/**
|
|
95
|
+
* Custom logger object. If not provided, the SDK will use the default `console.log` method for all log levels.
|
|
96
|
+
*/
|
|
97
|
+
logger?: SplitIO.Logger;
|
|
94
98
|
}
|
|
95
99
|
/**
|
|
96
100
|
* Common settings properties for SDKs with synchronous API (standalone and localhost modes).
|
|
@@ -141,6 +145,8 @@ interface IPluggableSharedSettings {
|
|
|
141
145
|
* config.debug = ErrorLogger()
|
|
142
146
|
* ```
|
|
143
147
|
*
|
|
148
|
+
* When combined with the `logger` option, any log level other than `NONE` (false) will be set to `DEBUG` (true), delegating log level control to the custom logger.
|
|
149
|
+
*
|
|
144
150
|
* @defaultValue `false`
|
|
145
151
|
*/
|
|
146
152
|
debug?: boolean | SplitIO.LogLevel | SplitIO.ILogger;
|
|
@@ -164,6 +170,8 @@ interface INonPluggableSharedSettings {
|
|
|
164
170
|
* config.debug = 'WARN'
|
|
165
171
|
* ```
|
|
166
172
|
*
|
|
173
|
+
* When combined with the `logger` option, any log level other than `NONE` (false) will be set to `DEBUG` (true), delegating log level control to the custom logger.
|
|
174
|
+
*
|
|
167
175
|
* @defaultValue `false`
|
|
168
176
|
*/
|
|
169
177
|
debug?: boolean | SplitIO.LogLevel;
|
|
@@ -587,6 +595,7 @@ declare namespace SplitIO {
|
|
|
587
595
|
telemetry: string;
|
|
588
596
|
};
|
|
589
597
|
readonly integrations?: IntegrationFactory[];
|
|
598
|
+
readonly logger?: Logger;
|
|
590
599
|
readonly debug: boolean | LogLevel | ILogger;
|
|
591
600
|
readonly version: string;
|
|
592
601
|
/**
|
|
@@ -617,6 +626,15 @@ declare namespace SplitIO {
|
|
|
617
626
|
* Log levels.
|
|
618
627
|
*/
|
|
619
628
|
type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';
|
|
629
|
+
/**
|
|
630
|
+
* Custom logger interface.
|
|
631
|
+
*/
|
|
632
|
+
interface Logger {
|
|
633
|
+
debug(message: string): any;
|
|
634
|
+
info(message: string): any;
|
|
635
|
+
warn(message: string): any;
|
|
636
|
+
error(message: string): any;
|
|
637
|
+
}
|
|
620
638
|
/**
|
|
621
639
|
* Logger API
|
|
622
640
|
*/
|
|
@@ -631,8 +649,16 @@ declare namespace SplitIO {
|
|
|
631
649
|
disable(): void;
|
|
632
650
|
/**
|
|
633
651
|
* Sets a log level for the SDK logs.
|
|
652
|
+
*
|
|
653
|
+
* @param logLevel - The log level to set.
|
|
634
654
|
*/
|
|
635
655
|
setLogLevel(logLevel: LogLevel): void;
|
|
656
|
+
/**
|
|
657
|
+
* Sets a custom logger for the SDK logs.
|
|
658
|
+
*
|
|
659
|
+
* @param logger - The custom logger to set, or `undefined` to remove the custom logger and fall back to the default `console.log` method.
|
|
660
|
+
*/
|
|
661
|
+
setLogger(logger?: Logger): void;
|
|
636
662
|
/**
|
|
637
663
|
* Log level constants. Use this to pass them to setLogLevel function.
|
|
638
664
|
*/
|