Skip to content

Commit ae169e8

Browse files
committed
break up log
1 parent 34747dd commit ae169e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+379
-405
lines changed

src/core/executors/CustomEventOperationExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getResponseStatusType,
88
ResponseStatusType,
99
} from 'src/shared/helpers/network';
10-
import Log from 'src/shared/libraries/Log';
10+
import { debug } from 'src/shared/libraries/log2';
1111
import { VERSION } from 'src/shared/utils/env';
1212
import { OPERATION_NAME } from '../constants';
1313
import { Operation } from '../operations/Operation';
@@ -34,7 +34,7 @@ export class CustomEventsOperationExecutor implements IOperationExecutor {
3434
}
3535

3636
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
37-
Log._debug(
37+
debug(
3838
`CustomEventsOperationExecutor(operations: ${JSON.stringify(
3939
operations,
4040
)})`,

src/core/executors/IdentityOperationExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getResponseStatusType,
99
ResponseStatusType,
1010
} from 'src/shared/helpers/network';
11-
import Log from 'src/shared/libraries/Log';
11+
import { debug } from 'src/shared/libraries/log2';
1212
import { IdentityConstants, OPERATION_NAME } from '../constants';
1313
import { type IdentityModelStore } from '../modelStores/IdentityModelStore';
1414
import { type NewRecordsState } from '../operationRepo/NewRecordsState';
@@ -40,7 +40,7 @@ export class IdentityOperationExecutor implements IOperationExecutor {
4040
}
4141

4242
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
43-
Log._debug(
43+
debug(
4444
`IdentityOperationExecutor(operations: ${JSON.stringify(operations)})`,
4545
);
4646

src/core/executors/LoginUserOperationExecutor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getResponseStatusType,
99
ResponseStatusType,
1010
} from 'src/shared/helpers/network';
11-
import Log from 'src/shared/libraries/Log';
11+
import { debug, error } from 'src/shared/libraries/log2';
1212
import { checkAndTriggerUserChanged } from 'src/shared/listeners';
1313
import { IdentityConstants, OPERATION_NAME } from '../constants';
1414
import { type IPropertiesModelKeys } from '../models/PropertiesModel';
@@ -62,7 +62,7 @@ export class LoginUserOperationExecutor implements IOperationExecutor {
6262
}
6363

6464
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
65-
Log._debug(
65+
debug(
6666
`LoginUserOperationExecutor(operation: ${JSON.stringify(operations)})`,
6767
);
6868
const startingOp = operations[0];
@@ -122,11 +122,11 @@ export class LoginUserOperationExecutor implements IOperationExecutor {
122122
}
123123

124124
case ExecutionResult._FailConflict:
125-
Log._debug(`Handling 409 for externalId: ${loginUserOp._externalId}`);
125+
debug(`Handling 409 for externalId: ${loginUserOp._externalId}`);
126126
return this._createUser(loginUserOp, operations);
127127

128128
case ExecutionResult._FailNoretry:
129-
Log._error(
129+
error(
130130
`Recovering from SetAlias failure for externalId: ${loginUserOp._externalId}`,
131131
);
132132
return this._createUser(loginUserOp, operations);

src/core/executors/RefreshUserOperationExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ResponseStatusType,
44
} from 'src/shared/helpers/network';
55
import { isPushSubscriptionType } from 'src/shared/helpers/subscription';
6-
import Log from 'src/shared/libraries/Log';
6+
import { debug } from 'src/shared/libraries/log2';
77
import { NotificationType } from 'src/shared/subscriptions/constants';
88
import { IdentityConstants, OPERATION_NAME } from '../constants';
99
import { IdentityModel } from '../models/IdentityModel';
@@ -52,7 +52,7 @@ export class RefreshUserOperationExecutor implements IOperationExecutor {
5252
}
5353

5454
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
55-
Log._debug(
55+
debug(
5656
`RefreshUserOperationExecutor(operation: ${JSON.stringify(operations)})`,
5757
);
5858

src/core/executors/SubscriptionOperationExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getResponseStatusType,
88
ResponseStatusType,
99
} from 'src/shared/helpers/network';
10-
import Log from 'src/shared/libraries/Log';
10+
import { debug } from 'src/shared/libraries/log2';
1111
import { IdentityConstants, OPERATION_NAME } from '../constants';
1212
import { type SubscriptionModelStore } from '../modelStores/SubscriptionModelStore';
1313
import { type NewRecordsState } from '../operationRepo/NewRecordsState';
@@ -53,7 +53,7 @@ export class SubscriptionOperationExecutor implements IOperationExecutor {
5353
}
5454

5555
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
56-
Log._debug(`SubscriptionOperationExecutor(operations: ${operations})`);
56+
debug(`SubscriptionOperationExecutor(operations: ${operations})`);
5757

5858
const startingOp = operations[0];
5959
if (startingOp instanceof CreateSubscriptionOperation)

src/core/executors/UpdateUserOperationExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
getResponseStatusType,
33
ResponseStatusType,
44
} from 'src/shared/helpers/network';
5-
import Log from 'src/shared/libraries/Log';
5+
import { debug } from 'src/shared/libraries/log2';
66
import { IdentityConstants, OPERATION_NAME } from '../constants';
77
import { type IPropertiesModelKeys } from '../models/PropertiesModel';
88
import { type IdentityModelStore } from '../modelStores/IdentityModelStore';
@@ -78,7 +78,7 @@ export class UpdateUserOperationExecutor implements IOperationExecutor {
7878
}
7979

8080
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
81-
Log._debug(`UpdateUserOperationExecutor(operation: ${operations})`);
81+
debug(`UpdateUserOperationExecutor(operation: ${operations})`);
8282

8383
const { appId, onesignalId, propertiesObject, refreshDeviceMetadata } =
8484
this._processOperations(operations);

src/core/modelRepo/OperationModelStore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IDBStoreName } from 'src/shared/database/types';
2-
import Log from 'src/shared/libraries/Log';
2+
import { error } from 'src/shared/libraries/log2';
33
import { OPERATION_NAME } from '../constants';
44
import { CreateSubscriptionOperation } from '../operations/CreateSubscriptionOperation';
55
import { DeleteAliasOperation } from '../operations/DeleteAliasOperation';
@@ -27,7 +27,7 @@ export class OperationModelStore extends ModelStore<Operation> {
2727

2828
_create(jsonObject?: { name?: string } | null): Operation | null {
2929
if (jsonObject === null) {
30-
Log._error('null jsonObject sent to OperationModelStore.create');
30+
error('null jsonObject sent to OperationModelStore.create');
3131
return null;
3232
}
3333

@@ -96,15 +96,15 @@ export class OperationModelStore extends ModelStore<Operation> {
9696
} {
9797
const operationName = object?.name;
9898
if (!operationName) {
99-
Log._error("jsonObject must have 'name' attribute");
99+
error("jsonObject must have 'name' attribute");
100100
return false;
101101
}
102102

103103
const excluded = new Set<string>([OPERATION_NAME._LoginUser]);
104104

105105
// Must have onesignalId if it is not one of the excluded operations above
106106
if (!object.onesignalId && !excluded.has(operationName)) {
107-
Log._error(
107+
error(
108108
`${operationName} jsonObject must have 'onesignalId' attribute`,
109109
);
110110
return false;

src/core/operationRepo/OperationRepo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { APP_ID, ONESIGNAL_ID, SUB_ID } from '__test__/constants';
22
import { db } from 'src/shared/database/client';
33
import type { IndexedDBSchema } from 'src/shared/database/types';
44
import { setConsentRequired } from 'src/shared/helpers/localStorage';
5-
import Log from 'src/shared/libraries/Log';
5+
import * as Log from 'src/shared/libraries/log2';
66
import { SubscriptionType } from 'src/shared/subscriptions/constants';
77
import { describe, expect, type Mock, vi } from 'vitest';
88
import { OperationModelStore } from '../modelRepo/OperationModelStore';
@@ -21,7 +21,7 @@ import {
2121
import { NewRecordsState } from './NewRecordsState';
2222
import { OperationRepo } from './OperationRepo';
2323

24-
vi.spyOn(Log, '_error').mockImplementation((msg) => {
24+
vi.spyOn(Log, 'error').mockImplementation((msg) => {
2525
if (typeof msg === 'string' && msg.includes('Operation execution failed'))
2626
return '';
2727
return msg;

src/core/operationRepo/OperationRepo.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'src/core/types/operation';
77
import { db } from 'src/shared/database/client';
88
import { delay } from 'src/shared/helpers/general';
9-
import Log from 'src/shared/libraries/Log';
9+
import { debug, error } from 'src/shared/libraries/log2';
1010
import { type OperationModelStore } from '../modelRepo/OperationModelStore';
1111
import { GroupComparisonType, type Operation } from '../operations/Operation';
1212
import {
@@ -80,11 +80,11 @@ export class OperationRepo implements IOperationRepo, IStartableService {
8080
public _pause(): void {
8181
clearInterval(this._timerID);
8282
this._timerID = undefined;
83-
Log._debug('OperationRepo: Paused');
83+
debug('OperationRepo: Paused');
8484
}
8585

8686
public _enqueue(operation: Operation): void {
87-
Log._debug(`OperationRepo.enqueue(operation: ${operation})`);
87+
debug(`OperationRepo.enqueue(operation: ${operation})`);
8888

8989
this._internalEnqueue(
9090
{
@@ -97,7 +97,7 @@ export class OperationRepo implements IOperationRepo, IStartableService {
9797
}
9898

9999
public async _enqueueAndWait(operation: Operation): Promise<void> {
100-
Log._debug(`OperationRepo.enqueueAndWaitoperation: ${operation})`);
100+
debug(`OperationRepo.enqueueAndWaitoperation: ${operation})`);
101101

102102
await new Promise<void>((resolve, reject) => {
103103
this._internalEnqueue(
@@ -121,7 +121,7 @@ export class OperationRepo implements IOperationRepo, IStartableService {
121121
(item) => item.operation._modelId === queueItem.operation._modelId,
122122
);
123123
if (hasExisting) {
124-
Log._debug(
124+
debug(
125125
`OperationRepo: internalEnqueue - operation.modelId: ${queueItem.operation._modelId} already exists in the queue.`,
126126
);
127127
return;
@@ -143,7 +143,7 @@ export class OperationRepo implements IOperationRepo, IStartableService {
143143
let runningOps = false;
144144

145145
this._timerID = setInterval(async () => {
146-
if (runningOps) return Log._debug('Operations in progress');
146+
if (runningOps) return debug('Operations in progress');
147147

148148
const ops = this._getNextOps(this._executeBucket);
149149

@@ -172,7 +172,7 @@ export class OperationRepo implements IOperationRepo, IStartableService {
172172
const response = await executor._execute(operations);
173173
const idTranslations = response._idTranslations;
174174

175-
Log._debug(`OperationRepo: execute response = ${response._result}`);
175+
debug(`OperationRepo: execute response = ${response._result}`);
176176

177177
// Handle ID translations
178178
if (idTranslations) {
@@ -199,7 +199,7 @@ export class OperationRepo implements IOperationRepo, IStartableService {
199199
case ExecutionResult._FailUnauthorized:
200200
case ExecutionResult._FailNoretry:
201201
case ExecutionResult._FailConflict:
202-
Log._error(`Operation execution failed without retry: ${operations}`);
202+
error(`Operation execution failed without retry: ${operations}`);
203203
ops.forEach((op) => {
204204
this._operationModelStore._remove(op.operation._modelId);
205205
});
@@ -218,7 +218,7 @@ export class OperationRepo implements IOperationRepo, IStartableService {
218218
break;
219219

220220
case ExecutionResult._FailRetry:
221-
Log._error(`Operation execution failed, retrying: ${operations}`);
221+
error(`Operation execution failed, retrying: ${operations}`);
222222
// Add back all operations to front of queue
223223
[...ops].reverse().forEach((op) => {
224224
removeOpFromDB(op.operation);
@@ -231,7 +231,7 @@ export class OperationRepo implements IOperationRepo, IStartableService {
231231
break;
232232

233233
case ExecutionResult._FailPauseOpRepo:
234-
Log._error(`Operation failed, pausing ops:${operations}`);
234+
error(`Operation failed, pausing ops:${operations}`);
235235
this._pause();
236236
ops.forEach((op) => op.resolver?.(false));
237237
[...ops].reverse().forEach((op) => {
@@ -263,7 +263,7 @@ export class OperationRepo implements IOperationRepo, IStartableService {
263263
await delay(OP_REPO_POST_CREATE_DELAY);
264264
}
265265
} catch (e) {
266-
Log._error(`Error attempting to execute operation: ${ops}`, e);
266+
error(`Error attempting to execute operation: ${ops}`, e);
267267

268268
// On failure remove operations from store
269269
ops.forEach((op) => {
@@ -277,14 +277,14 @@ export class OperationRepo implements IOperationRepo, IStartableService {
277277
retries: number,
278278
retryAfterSeconds?: number,
279279
): Promise<void> {
280-
Log._debug(`retryAfterSeconds: ${retryAfterSeconds}`);
280+
debug(`retryAfterSeconds: ${retryAfterSeconds}`);
281281
const retryAfterSecondsMs = (retryAfterSeconds || 0) * 1000;
282282
const delayForOnRetries = retries * OP_REPO_DEFAULT_FAIL_RETRY_BACKOFF;
283283
const delayFor = Math.max(delayForOnRetries, retryAfterSecondsMs);
284284

285285
if (delayFor < 1) return;
286286

287-
Log._error(`Operations being delay for: ${delayFor} ms`);
287+
error(`Operations being delay for: ${delayFor} ms`);
288288
await delay(delayFor);
289289
}
290290

src/entries/pageSdkInit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { APP_ID } from '__test__/constants';
22
import { TestEnvironment } from '__test__/support/environment/TestEnvironment';
33
import { server } from '__test__/support/mocks/server';
44
import { http, HttpResponse } from 'msw';
5-
import Log from 'src/shared/libraries/Log';
5+
import * as Log from 'src/shared/libraries/log2';
66

77
// need to wait for full OperationRepo rework
88
describe('pageSdkInit', () => {
@@ -42,7 +42,7 @@ describe('pageSdkInit', () => {
4242
});
4343

4444
test('can process deferred items long after page init', async () => {
45-
vi.spyOn(Log, '_error').mockImplementation(() => '');
45+
vi.spyOn(Log, 'error').mockImplementation(() => '');
4646
await import('./pageSdkInit');
4747
const initSpy = vi.spyOn(window.OneSignal, 'init');
4848

0 commit comments

Comments
 (0)