Skip to content

refactor: Integrate logging package #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 57 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
92e3ab7
utils integrated
ozayr-zaviar Mar 2, 2022
37cab7b
logging integrated
ozayr-zaviar Mar 14, 2022
1d5368c
testcases fix
ozayr-zaviar Mar 14, 2022
82b0fa1
revert logging
ozayr-zaviar Mar 25, 2022
2843dcc
utils merged in optimizely sdk
ozayr-zaviar Mar 25, 2022
8574c7e
small changes removed
ozayr-zaviar Mar 25, 2022
f725a21
Merge branch 'master' into uzair/consolidate-packages
ozayr-zaviar Mar 28, 2022
28905d0
ts config added because jest and mocha use similar declarations
ozayr-zaviar Mar 28, 2022
11518e1
type warning fixed
ozayr-zaviar Mar 28, 2022
d3371ce
more types fixed
ozayr-zaviar Mar 28, 2022
da73e11
fix
ozayr-zaviar Mar 28, 2022
069e501
fix
ozayr-zaviar Mar 28, 2022
bc6d5fb
fix
ozayr-zaviar Mar 28, 2022
3b758bd
type defined
ozayr-zaviar Mar 28, 2022
73e1db8
type fix
ozayr-zaviar Mar 28, 2022
d41146d
Merge branch 'master' into uzair/consolidate-packages
ozayr-zaviar Apr 12, 2022
550c3ba
headers updated
ozayr-zaviar Apr 12, 2022
39b5d69
fix
ozayr-zaviar Apr 12, 2022
d00a828
correct notification type imported
ozayr-zaviar Apr 12, 2022
c958cda
comment addressed
ozayr-zaviar Apr 12, 2022
c36dee9
headers updated and notification center moved
ozayr-zaviar Apr 13, 2022
19d1ca0
comments addressed
ozayr-zaviar Apr 14, 2022
6622d21
removed Notification center interface
ozayr-zaviar Apr 18, 2022
71f7e14
notification center renamed
ozayr-zaviar Apr 18, 2022
4b9c124
notification type corrected
ozayr-zaviar Apr 18, 2022
9e3d8d4
renamed a conflicting interface
zashraf1985 Apr 19, 2022
bef10a0
removed unused line
zashraf1985 Apr 19, 2022
dcdd371
comments addressed
ozayr-zaviar Apr 21, 2022
4fc4b51
fns exported in same import
ozayr-zaviar Apr 21, 2022
201800e
intergrate logging
ozayr-zaviar Mar 14, 2022
e55fdc0
testcases fix
ozayr-zaviar Mar 14, 2022
0146bf1
logging rollup corrected
ozayr-zaviar Mar 25, 2022
65a3f0a
rollup fixed
ozayr-zaviar Apr 26, 2022
d594c09
fixed some build issues
zashraf1985 Apr 26, 2022
a8e7858
comment addressed
ozayr-zaviar Apr 28, 2022
def50b4
headers updated
ozayr-zaviar Apr 28, 2022
0d088e7
logging path corrected
ozayr-zaviar Apr 28, 2022
0bb709c
Merge branch 'master' into uzair/consolidate-packages
ozayr-zaviar Apr 28, 2022
f352bc6
Merge branch 'uzair/consolidate-packages' into uzair/consolidate-log
ozayr-zaviar Apr 28, 2022
f36baf4
comments addressed
ozayr-zaviar May 5, 2022
aa90124
Merge branch 'uzair/consolidate-packages' into uzair/consolidate-log
ozayr-zaviar May 9, 2022
ac3451b
Merge branch 'master' into uzair/consolidate-log
ozayr-zaviar May 24, 2022
d82888a
Update package-lock.json
ozayr-zaviar May 24, 2022
4234caf
previous utils paths fixed
ozayr-zaviar May 24, 2022
bc7d7e6
lint fix
ozayr-zaviar May 24, 2022
98962c1
test
ozayr-zaviar May 24, 2022
4836a2c
test
ozayr-zaviar May 24, 2022
ef5bc91
revert
ozayr-zaviar May 24, 2022
a47ce8d
browser tests fixed
ozayr-zaviar Jun 2, 2022
9accd13
entry level packages fixed
ozayr-zaviar Jun 2, 2022
685f03e
fixes
ozayr-zaviar Jun 2, 2022
2529776
Merge branch 'master' into uzair/consolidate-log
zashraf1985 Jun 7, 2022
6132ed9
headers updated
ozayr-zaviar Jun 10, 2022
10adac2
Merge branch 'master' into uzair/consolidate-log
zashraf1985 Jul 28, 2022
72bc98b
fixed helper issue
ozayr-zaviar Aug 1, 2022
0d8be1e
Merge branch 'uzair/consolidate-log' of github.com:optimizely/javascr…
Aug 1, 2022
5963ea8
removed unused dependencies from package.json
zashraf1985 Aug 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
import sinon from 'sinon';
import { assert } from 'chai';
import { getLogger } from '@optimizely/js-sdk-logging';
import { sprintf } from '../../utils/fns';
import { getLogger } from '../../modules/logging';

import { createAudienceEvaluator } from './index';
import * as conditionTreeEvaluator from '../condition_tree_evaluator';
Expand Down
4 changes: 2 additions & 2 deletions packages/optimizely-sdk/lib/core/audience_evaluator/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016, 2018-2021, Optimizely
* Copyright 2016, 2018-2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getLogger } from '@optimizely/js-sdk-logging';
import { getLogger } from '../../modules/logging';

import fns from '../../utils/fns';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/core/bucketer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
import { sprintf } from '../../utils/fns';
import murmurhash from 'murmurhash';
import { LogHandler } from '@optimizely/js-sdk-logging';
import { LogHandler } from '../../modules/logging';
import {
DecisionResponse,
BucketerParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
LOG_LEVEL,
LOG_MESSAGES,
} from '../../utils/enums';
import * as logging from '@optimizely/js-sdk-logging';
import * as logging from '../../modules/logging';
import * as customAttributeEvaluator from './';

var browserConditionSafari = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2018-2019, 2020 Optimizely, Inc. and contributors *
* Copyright 2018-2019, 2020, 2022, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/
import { getLogger } from '@optimizely/js-sdk-logging';
import { getLogger } from '../../modules/logging';
import { UserAttributes, Condition } from '../../shared_types';

import fns from '../../utils/fns';
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/core/decision_service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/
import { LogHandler } from '@optimizely/js-sdk-logging';
import { LogHandler } from '../../modules/logging';
import { sprintf } from '../../utils/fns';

import fns from '../../utils/fns';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019-2021, Optimizely
* Copyright 2019-2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getLogger } from '@optimizely/js-sdk-logging';
import { getLogger } from '../../modules/logging';

import fns from '../../utils/fns';
import * as eventTagUtils from '../../utils/event_tag_utils';
Expand Down
4 changes: 2 additions & 2 deletions packages/optimizely-sdk/lib/core/event_builder/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2021, Optimizely
* Copyright 2016-2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LoggerFacade } from '@optimizely/js-sdk-logging';
import { LoggerFacade } from '../../modules/logging';
import { EventV1 as CommonEventParams } from '@optimizely/js-sdk-event-processor';

import fns from '../../utils/fns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';
import { LogHandler, ErrorHandler } from '../../modules/logging';
import { objectValues } from '../../utils/fns';
import { NotificationListener, ListenerPayload } from '../../shared_types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import sinon from 'sinon';
import { assert } from 'chai';
import { forEach, cloneDeep } from 'lodash';
import { getLogger } from '@optimizely/js-sdk-logging';
import { sprintf } from '../../utils/fns';
import { getLogger } from '../../modules/logging';

import fns from '../../utils/fns';
import projectConfig from './';
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/core/project_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '../../utils/enums';
import configValidator from '../../utils/config_validator';

import { LogHandler } from '@optimizely/js-sdk-logging';
import { LogHandler } from '../../modules/logging';
import {
Audience,
Experiment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import sinon from 'sinon';
import { assert } from 'chai';
import { cloneDeep } from 'lodash';

import * as logging from '@optimizely/js-sdk-logging';
import { sprintf } from '../../utils/fns';
import * as logging from '../../modules/logging';
import * as datafileManager from '@optimizely/js-sdk-datafile-manager';

import * as projectConfig from './index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getLogger } from '@optimizely/js-sdk-logging';
import { getLogger } from '../../modules/logging';
import { sprintf } from '../../utils/fns';

import { ERROR_MESSAGES } from '../../utils/enums';
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/index.browser.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as logging from '@optimizely/js-sdk-logging';
import logging from './modules/logging/logger';

import { assert } from 'chai';
import sinon from 'sinon';
Expand Down
18 changes: 10 additions & 8 deletions packages/optimizely-sdk/lib/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import logHelper from './modules/logging/logger';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you need to introduce the concept of logHelper here. Why importing directly from ./modules/loggin does not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Karma browser test was not able to locate the package unless it is defined in the default.

import {
getLogger,
setLogHandler,
setLogLevel,
setErrorHandler,
getErrorHandler,
LogLevel
} from '@optimizely/js-sdk-logging';
} from './modules/logging';
import { LocalStoragePendingEventsDispatcher } from '@optimizely/js-sdk-event-processor';
import configValidator from './utils/config_validator';
import defaultErrorHandler from './plugins/error_handler';
Expand All @@ -35,8 +34,8 @@ import { OptimizelyDecideOption, Client, Config } from './shared_types';
import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager';

const logger = getLogger();
setLogHandler(loggerPlugin.createLogger());
setLogLevel(LogLevel.INFO);
logHelper.setLogHandler(loggerPlugin.createLogger());
logHelper.setLogLevel(LogLevel.INFO);

const MODULE_NAME = 'INDEX_BROWSER';
const DEFAULT_EVENT_BATCH_SIZE = 10;
Expand All @@ -60,12 +59,12 @@ const createInstance = function(config: Config): Client | null {
setErrorHandler(config.errorHandler);
}
if (config.logger) {
setLogHandler(config.logger);
logHelper.setLogHandler(config.logger);
// respect the logger's shouldLog functionality
setLogLevel(LogLevel.NOTSET);
logHelper.setLogLevel(LogLevel.NOTSET);
}
if (config.logLevel !== undefined) {
setLogLevel(config.logLevel);
logHelper.setLogLevel(config.logLevel);
}

try {
Expand Down Expand Up @@ -160,6 +159,9 @@ const __internalResetRetryState = function(): void {
/**
* Entry point into the Optimizely Browser SDK
*/

const setLogHandler = logHelper.setLogHandler
const setLogLevel = logHelper.setLogLevel
export {
loggerPlugin as logging,
defaultErrorHandler as errorHandler,
Expand Down
8 changes: 4 additions & 4 deletions packages/optimizely-sdk/lib/index.lite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
import {
getLogger,
setLogHandler,
setLogLevel,
setErrorHandler,
getErrorHandler,
LogLevel
} from '@optimizely/js-sdk-logging';
LogLevel,
setLogHandler,
setLogLevel
} from './modules/logging';
import configValidator from './utils/config_validator';
import defaultErrorHandler from './plugins/error_handler';
import noOpEventDispatcher from './plugins/event_dispatcher/no_op';
Expand Down
8 changes: 4 additions & 4 deletions packages/optimizely-sdk/lib/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
***************************************************************************/
import {
getLogger,
setLogHandler,
setLogLevel,
setErrorHandler,
getErrorHandler,
LogLevel
} from '@optimizely/js-sdk-logging';
LogLevel,
setLogHandler,
setLogLevel
} from './modules/logging';
import Optimizely from './optimizely';
import * as enums from './utils/enums';
import * as loggerPlugin from './plugins/logger';
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/index.react_native.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { assert } from 'chai';
import sinon from 'sinon';
import * as logging from '@optimizely/js-sdk-logging';
import * as logging from './modules/logging/logger';
import * as eventProcessor from './plugins/event_processor';

import Optimizely from './optimizely';
Expand Down
8 changes: 4 additions & 4 deletions packages/optimizely-sdk/lib/index.react_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
import {
getLogger,
setLogHandler,
setLogLevel,
setErrorHandler,
getErrorHandler,
LogLevel
} from '@optimizely/js-sdk-logging';
LogLevel,
setLogHandler,
setLogLevel
} from './modules/logging';
import * as enums from './utils/enums';
import Optimizely from './optimizely';
import configValidator from './utils/config_validator';
Expand Down
67 changes: 67 additions & 0 deletions packages/optimizely-sdk/lib/modules/logging/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright 2019, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @export
* @interface ErrorHandler
*/
export interface ErrorHandler {
/**
* @param {Error} exception
* @memberof ErrorHandler
*/
handleError(exception: Error): void
}

/**
* @export
* @class NoopErrorHandler
* @implements {ErrorHandler}
*/
export class NoopErrorHandler implements ErrorHandler {
/**
* @param {Error} exception
* @memberof NoopErrorHandler
*/
handleError(exception: Error): void {
// no-op
return
}
}

let globalErrorHandler: ErrorHandler = new NoopErrorHandler()

/**
* @export
* @param {ErrorHandler} handler
*/
export function setErrorHandler(handler: ErrorHandler): void {
globalErrorHandler = handler
}

/**
* @export
* @returns {ErrorHandler}
*/
export function getErrorHandler(): ErrorHandler {
return globalErrorHandler
}

/**
* @export
*/
export function resetErrorHandler(): void {
globalErrorHandler = new NoopErrorHandler()
}
18 changes: 18 additions & 0 deletions packages/optimizely-sdk/lib/modules/logging/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright 2019, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './errorHandler'
export * from './models'
export * from './logger'
Loading