Skip to content

Commit 5a424f7

Browse files
authored
feat: Migrate logger to js-toolkit logger implementation (#1959)
### 💡 Overview - Migrated usage of `getLogger` to new syntax where the first tag is considered as scope and the subsequent are tags. - Introduced new configuration option: `logOptions?: ConfigureLoggersOptions<string>` which allows the consumers to configure the loggers per scope - Marked `logger` and `logLevel` as deprecated and in first implementation setting them as default `level` and `level` in `configureLoggers` ### 📝 Implementation notes 📑 Docs: [GetStream/docs-content#673]
1 parent 0ee1a30 commit 5a424f7

File tree

77 files changed

+681
-739
lines changed

Some content is hidden

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

77 files changed

+681
-739
lines changed

packages/client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"@protobuf-ts/runtime": "^2.11.1",
3030
"@protobuf-ts/runtime-rpc": "^2.11.1",
3131
"@protobuf-ts/twirp-transport": "^2.11.1",
32-
"@stream-io/worker-timer": "^1.2.4",
32+
"@stream-io/logger": "^2.0.0",
33+
"@stream-io/worker-timer": "^1.2.5",
3334
"axios": "^1.12.2",
3435
"rxjs": "~7.8.2",
3536
"sdp-transform": "^2.15.0",

packages/client/src/Call.ts

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
createSubscription,
2626
getCurrentValue,
2727
} from './store/rxUtils';
28+
import { ScopedLogger, videoLoggerSystem } from './logger';
2829
import type {
2930
AcceptCallResponse,
3031
BlockUserRequest,
@@ -139,12 +140,10 @@ import {
139140
AllCallEvents,
140141
CallEventListener,
141142
ErrorFromResponse,
142-
Logger,
143143
RejectReason,
144144
StreamCallEvent,
145145
} from './coordinator/connection/types';
146146
import { getClientDetails } from './helpers/client-details';
147-
import { getLogger } from './logger';
148147
import {
149148
CameraManager,
150149
MicrophoneManager,
@@ -229,7 +228,7 @@ export class Call {
229228
*/
230229
readonly permissionsContext = new PermissionsContext();
231230
readonly tracer = new Tracer(null);
232-
readonly logger: Logger;
231+
readonly logger: ScopedLogger;
233232

234233
/**
235234
* The event dispatcher instance dedicated to this Call instance.
@@ -312,7 +311,7 @@ export class Call {
312311
this.streamClient = streamClient;
313312
this.clientStore = clientStore;
314313
this.streamClientBasePath = `/call/${this.type}/${this.id}`;
315-
this.logger = getLogger(['Call']);
314+
this.logger = videoLoggerSystem.getLogger('Call');
316315

317316
const callTypeConfig = CallTypes.get(type);
318317
const participantSorter =
@@ -396,9 +395,9 @@ export class Call {
396395
if (!blockedUserIds || blockedUserIds.length === 0) return;
397396
const currentUserId = this.currentUserId;
398397
if (currentUserId && blockedUserIds.includes(currentUserId)) {
399-
this.logger('info', 'Leaving call because of being blocked');
398+
this.logger.info('Leaving call because of being blocked');
400399
await this.leave({ message: 'user blocked' }).catch((err) => {
401-
this.logger('error', 'Error leaving call after being blocked', err);
400+
this.logger.error('Error leaving call after being blocked', err);
402401
});
403402
}
404403
}),
@@ -442,8 +441,7 @@ export class Call {
442441
!hasPending(this.joinLeaveConcurrencyTag)
443442
) {
444443
this.leave().catch(() => {
445-
this.logger(
446-
'error',
444+
this.logger.error(
447445
'Could not leave a call that was accepted or rejected elsewhere',
448446
);
449447
});
@@ -526,8 +524,7 @@ export class Call {
526524
break;
527525
}
528526
} catch (err) {
529-
this.logger(
530-
'error',
527+
this.logger.error(
531528
`Can't disable mic/camera/screenshare after revoked permissions`,
532529
err,
533530
);
@@ -886,12 +883,12 @@ export class Call {
886883
maxJoinRetries = Math.max(maxJoinRetries, 1);
887884
for (let attempt = 0; attempt < maxJoinRetries; attempt++) {
888885
try {
889-
this.logger('trace', `Joining call (${attempt})`, this.cid);
886+
this.logger.trace(`Joining call (${attempt})`, this.cid);
890887
await this.doJoin(data);
891888
delete joinData.migrating_from;
892889
break;
893890
} catch (err) {
894-
this.logger('warn', `Failed to join call (${attempt})`, this.cid);
891+
this.logger.warn(`Failed to join call (${attempt})`, this.cid);
895892
if (err instanceof ErrorFromResponse && err.unrecoverable) {
896893
// if the error is unrecoverable, we should not retry as that signals
897894
// that connectivity is good, but the coordinator doesn't allow the user
@@ -927,7 +924,7 @@ export class Call {
927924

928925
this.joinCallData = data;
929926

930-
this.logger('debug', 'Starting join flow');
927+
this.logger.debug('Starting join flow');
931928
this.state.setCallingState(CallingState.JOINING);
932929

933930
const performingMigration =
@@ -1031,7 +1028,7 @@ export class Call {
10311028
);
10321029
}
10331030
} catch (error) {
1034-
this.logger('warn', 'Join SFU request failed', error);
1031+
this.logger.warn('Join SFU request failed', error);
10351032
sfuClient.close(
10361033
StreamSfuClient.JOIN_FAILED,
10371034
'Join request failed, connection considered unhealthy',
@@ -1103,7 +1100,7 @@ export class Call {
11031100
this.reconnectStrategy = WebsocketReconnectStrategy.UNSPECIFIED;
11041101
this.reconnectReason = '';
11051102

1106-
this.logger('info', `Joined call ${this.cid}`);
1103+
this.logger.info(`Joined call ${this.cid}`);
11071104
};
11081105

11091106
/**
@@ -1250,7 +1247,7 @@ export class Call {
12501247
onReconnectionNeeded: (kind, reason) => {
12511248
this.reconnect(kind, reason).catch((err) => {
12521249
const message = `[Reconnect] Error reconnecting after a subscriber error: ${reason}`;
1253-
this.logger('warn', message, err);
1250+
this.logger.warn(message, err);
12541251
});
12551252
},
12561253
});
@@ -1273,7 +1270,7 @@ export class Call {
12731270
onReconnectionNeeded: (kind, reason) => {
12741271
this.reconnect(kind, reason).catch((err) => {
12751272
const message = `[Reconnect] Error reconnecting after a publisher error: ${reason}`;
1276-
this.logger('warn', message, err);
1273+
this.logger.warn(message, err);
12771274
});
12781275
},
12791276
});
@@ -1358,7 +1355,7 @@ export class Call {
13581355
sfuClient: StreamSfuClient,
13591356
reason: string,
13601357
) => {
1361-
this.logger('debug', '[Reconnect] SFU signal connection closed');
1358+
this.logger.debug('[Reconnect] SFU signal connection closed');
13621359
const { callingState } = this.state;
13631360
if (
13641361
// SFU WS closed before we finished current join,
@@ -1381,7 +1378,7 @@ export class Call {
13811378
? WebsocketReconnectStrategy.FAST
13821379
: WebsocketReconnectStrategy.REJOIN;
13831380
this.reconnect(strategy, reason).catch((err) => {
1384-
this.logger('warn', '[Reconnect] Error reconnecting', err);
1381+
this.logger.warn('[Reconnect] Error reconnecting', err);
13851382
});
13861383
};
13871384

@@ -1427,8 +1424,7 @@ export class Call {
14271424
reconnectingTime / 1000 > this.disconnectionTimeoutSeconds;
14281425

14291426
if (shouldGiveUpReconnecting) {
1430-
this.logger(
1431-
'warn',
1427+
this.logger.warn(
14321428
'[Reconnect] Stopping reconnection attempts after reaching disconnection timeout',
14331429
);
14341430
await markAsReconnectingFailed();
@@ -1445,16 +1441,14 @@ export class Call {
14451441
// wait until the network is available
14461442
await this.networkAvailableTask?.promise;
14471443

1448-
this.logger(
1449-
'info',
1444+
this.logger.info(
14501445
`[Reconnect] Reconnecting with strategy ${WebsocketReconnectStrategy[this.reconnectStrategy]}`,
14511446
);
14521447

14531448
switch (this.reconnectStrategy) {
14541449
case WebsocketReconnectStrategy.UNSPECIFIED:
14551450
case WebsocketReconnectStrategy.DISCONNECT:
1456-
this.logger(
1457-
'debug',
1451+
this.logger.debug(
14581452
`[Reconnect] No-op strategy ${currentStrategy}`,
14591453
);
14601454
break;
@@ -1477,17 +1471,15 @@ export class Call {
14771471
break; // do-while loop, reconnection worked, exit the loop
14781472
} catch (error) {
14791473
if (this.state.callingState === CallingState.OFFLINE) {
1480-
this.logger(
1481-
'debug',
1474+
this.logger.debug(
14821475
`[Reconnect] Can't reconnect while offline, stopping reconnection attempts`,
14831476
);
14841477
break;
14851478
// we don't need to handle the error if the call is offline
14861479
// network change event will trigger the reconnection
14871480
}
14881481
if (error instanceof ErrorFromResponse && error.unrecoverable) {
1489-
this.logger(
1490-
'warn',
1482+
this.logger.warn(
14911483
`[Reconnect] Can't reconnect due to coordinator unrecoverable error`,
14921484
error,
14931485
);
@@ -1520,8 +1512,7 @@ export class Call {
15201512
: WebsocketReconnectStrategy.FAST;
15211513
this.reconnectStrategy = nextStrategy;
15221514

1523-
this.logger(
1524-
'info',
1515+
this.logger.info(
15251516
`[Reconnect] ${currentStrategy} (${this.reconnectAttempts}) failed. Attempting with ${WebsocketReconnectStrategy[nextStrategy]}`,
15261517
error,
15271518
);
@@ -1531,7 +1522,7 @@ export class Call {
15311522
this.state.callingState !== CallingState.RECONNECTING_FAILED &&
15321523
this.state.callingState !== CallingState.LEFT
15331524
);
1534-
this.logger('info', '[Reconnect] Reconnection flow finished');
1525+
this.logger.info('[Reconnect] Reconnection flow finished');
15351526
});
15361527
};
15371528

@@ -1633,7 +1624,7 @@ export class Call {
16331624
// handles the legacy "goAway" event
16341625
const unregisterGoAway = this.on('goAway', () => {
16351626
this.reconnect(WebsocketReconnectStrategy.MIGRATE, 'goAway').catch(
1636-
(err) => this.logger('warn', '[Reconnect] Error reconnecting', err),
1627+
(err) => this.logger.warn('[Reconnect] Error reconnecting', err),
16371628
);
16381629
});
16391630

@@ -1643,11 +1634,11 @@ export class Call {
16431634
if (strategy === WebsocketReconnectStrategy.UNSPECIFIED) return;
16441635
if (strategy === WebsocketReconnectStrategy.DISCONNECT) {
16451636
this.leave({ message: 'SFU instructed to disconnect' }).catch((err) => {
1646-
this.logger('warn', `Can't leave call after disconnect request`, err);
1637+
this.logger.warn(`Can't leave call after disconnect request`, err);
16471638
});
16481639
} else {
16491640
this.reconnect(strategy, error?.message || 'SFU Error').catch((err) => {
1650-
this.logger('warn', '[Reconnect] Error reconnecting', err);
1641+
this.logger.warn('[Reconnect] Error reconnecting', err);
16511642
});
16521643
}
16531644
});
@@ -1657,7 +1648,7 @@ export class Call {
16571648
(e) => {
16581649
this.tracer.trace('network.changed', e);
16591650
if (!e.online) {
1660-
this.logger('debug', '[Reconnect] Going offline');
1651+
this.logger.debug('[Reconnect] Going offline');
16611652
if (!this.hasJoinedOnce) return;
16621653
this.lastOfflineTimestamp = Date.now();
16631654
// create a new task that would resolve when the network is available
@@ -1674,8 +1665,7 @@ export class Call {
16741665
}
16751666

16761667
this.reconnect(strategy, 'Going online').catch((err) => {
1677-
this.logger(
1678-
'warn',
1668+
this.logger.warn(
16791669
'[Reconnect] Error reconnecting after going online',
16801670
err,
16811671
);
@@ -1685,7 +1675,7 @@ export class Call {
16851675
this.sfuStatsReporter?.stop();
16861676
this.state.setCallingState(CallingState.OFFLINE);
16871677
} else {
1688-
this.logger('debug', '[Reconnect] Going online');
1678+
this.logger.debug('[Reconnect] Going online');
16891679
this.sfuClient?.close(
16901680
StreamSfuClient.DISPOSE_OLD_SOCKET,
16911681
'Closing WS to reconnect after going online',
@@ -1875,14 +1865,12 @@ export class Call {
18751865
* @param options the options to use.
18761866
*/
18771867
updatePublishOptions = (options: ClientPublishOptions) => {
1878-
this.logger(
1879-
'warn',
1868+
this.logger.warn(
18801869
'[call.updatePublishOptions]: You are manually overriding the publish options for this call. ' +
18811870
'This is not recommended, and it can cause call stability/compatibility issues. Use with caution.',
18821871
);
18831872
if (this.state.callingState === CallingState.JOINED) {
1884-
this.logger(
1885-
'warn',
1873+
this.logger.warn(
18861874
'Updating publish options after joining the call does not have an effect',
18871875
);
18881876
}
@@ -1896,7 +1884,7 @@ export class Call {
18961884
*/
18971885
notifyNoiseCancellationStarting = async () => {
18981886
return this.sfuClient?.startNoiseCancellation().catch((err) => {
1899-
this.logger('warn', 'Failed to notify start of noise cancellation', err);
1887+
this.logger.warn('Failed to notify start of noise cancellation', err);
19001888
});
19011889
};
19021890

@@ -1907,7 +1895,7 @@ export class Call {
19071895
*/
19081896
notifyNoiseCancellationStopped = async () => {
19091897
return this.sfuClient?.stopNoiseCancellation().catch((err) => {
1910-
this.logger('warn', 'Failed to notify stop of noise cancellation', err);
1898+
this.logger.warn('Failed to notify stop of noise cancellation', err);
19111899
});
19121900
};
19131901

@@ -2489,7 +2477,7 @@ export class Call {
24892477
reason: 'timeout',
24902478
message: `ringing timeout - ${this.isCreatedByMe ? 'no one accepted' : `user didn't interact with incoming call screen`}`,
24912479
}).catch((err) => {
2492-
this.logger('error', 'Failed to drop call', err);
2480+
this.logger.error('Failed to drop call', err);
24932481
});
24942482
}, timeoutInMs);
24952483
};
@@ -2653,10 +2641,10 @@ export class Call {
26532641
publish: boolean,
26542642
) => {
26552643
await this.camera.apply(settings.video, publish).catch((err) => {
2656-
this.logger('warn', 'Camera init failed', err);
2644+
this.logger.warn('Camera init failed', err);
26572645
});
26582646
await this.microphone.apply(settings.audio, publish).catch((err) => {
2659-
this.logger('warn', 'Mic init failed', err);
2647+
this.logger.warn('Mic init failed', err);
26602648
});
26612649
};
26622650

0 commit comments

Comments
 (0)