diff --git a/spec/integ/sliding-sync-sdk.spec.ts b/spec/integ/sliding-sync-sdk.spec.ts index 449090a17..2a81fbf6a 100644 --- a/spec/integ/sliding-sync-sdk.spec.ts +++ b/spec/integ/sliding-sync-sdk.spec.ts @@ -126,7 +126,7 @@ describe("SlidingSyncSdk", () => { // assign client/httpBackend globals const setupClient = async (testOpts?: Partial) => { testOpts = testOpts || {}; - const syncOpts: SyncApiOptions = {}; + const syncOpts: SyncApiOptions = { logger }; const testClient = new TestClient(selfUserId, "DEVICE", selfAccessToken); httpBackend = testClient.httpBackend; client = testClient.client; diff --git a/spec/unit/ToDeviceMessageQueue.spec.ts b/spec/unit/ToDeviceMessageQueue.spec.ts index a3c86585e..ee3932119 100644 --- a/spec/unit/ToDeviceMessageQueue.spec.ts +++ b/spec/unit/ToDeviceMessageQueue.spec.ts @@ -5,6 +5,7 @@ import { getMockClientWithEventEmitter } from "../test-utils/client"; import { StubStore } from "../../src/store/stub"; import { type IndexedToDeviceBatch } from "../../src/models/ToDeviceMessage"; import { SyncState } from "../../src/sync"; +import { logger } from "../../src/logger.ts"; describe("onResumedSync", () => { let batch: IndexedToDeviceBatch | null; @@ -55,7 +56,7 @@ describe("onResumedSync", () => { } }); - queue = new ToDeviceMessageQueue(mockClient); + queue = new ToDeviceMessageQueue(mockClient, logger); }); it("resends queue after connectivity restored", async () => { diff --git a/spec/unit/pushprocessor.spec.ts b/spec/unit/pushprocessor.spec.ts index 2b70cbe57..117ed8e7b 100644 --- a/spec/unit/pushprocessor.spec.ts +++ b/spec/unit/pushprocessor.spec.ts @@ -28,6 +28,7 @@ import { TweakName, } from "../../src"; import { mockClientMethodsUser } from "../test-utils/client"; +import { logger } from "../../src/logger.ts"; const msc3914RoomCallRule: IPushRule = { rule_id: ".org.matrix.msc3914.rule.room.call", @@ -209,7 +210,7 @@ describe("NotificationService", function () { msgtype: "m.text", }, }); - matrixClient.pushRules = PushProcessor.rewriteDefaultRules(matrixClient.pushRules!); + matrixClient.pushRules = PushProcessor.rewriteDefaultRules(logger, matrixClient.pushRules!); pushProcessor = new PushProcessor(matrixClient); }); @@ -731,7 +732,7 @@ describe("Test PushProcessor.partsForDottedKey", function () { describe("rewriteDefaultRules", () => { it("should add default rules in the correct order", () => { - const pushRules = PushProcessor.rewriteDefaultRules({ + const pushRules = PushProcessor.rewriteDefaultRules(logger, { device: {}, global: { content: [], @@ -867,7 +868,7 @@ describe("rewriteDefaultRules", () => { }); it("should add missing msc3914 rule in correct place", () => { - const pushRules = PushProcessor.rewriteDefaultRules({ + const pushRules = PushProcessor.rewriteDefaultRules(logger, { device: {}, global: { // Sample push rules from a Synapse user. diff --git a/src/ToDeviceMessageQueue.ts b/src/ToDeviceMessageQueue.ts index 168584894..75f634c2e 100644 --- a/src/ToDeviceMessageQueue.ts +++ b/src/ToDeviceMessageQueue.ts @@ -15,7 +15,7 @@ limitations under the License. */ import { ToDeviceMessageId } from "./@types/event.ts"; -import { logger } from "./logger.ts"; +import { type Logger } from "./logger.ts"; import { type MatrixClient, ClientEvent } from "./client.ts"; import { type MatrixError } from "./http-api/index.ts"; import { @@ -40,7 +40,10 @@ export class ToDeviceMessageQueue { private retryTimeout: ReturnType | null = null; private retryAttempts = 0; - public constructor(private client: MatrixClient) {} + public constructor( + private client: MatrixClient, + private readonly logger: Logger, + ) {} public start(): void { this.running = true; @@ -67,7 +70,7 @@ export class ToDeviceMessageQueue { const msgmap = batchWithTxnId.batch.map( (msg) => `${msg.userId}/${msg.deviceId} (msgid ${msg.payload[ToDeviceMessageId]})`, ); - logger.info( + this.logger.info( `Enqueuing batch of to-device messages. type=${batch.eventType} txnid=${batchWithTxnId.txnId}`, msgmap, ); @@ -83,7 +86,7 @@ export class ToDeviceMessageQueue { if (this.sending || !this.running) return; - logger.debug("Attempting to send queued to-device messages"); + this.logger.debug("Attempting to send queued to-device messages"); this.sending = true; let headBatch: IndexedToDeviceBatch | null; @@ -99,7 +102,7 @@ export class ToDeviceMessageQueue { // Make sure we're still running after the async tasks: if not, stop. if (!this.running) return; - logger.debug("All queued to-device messages sent"); + this.logger.debug("All queued to-device messages sent"); } catch (e) { ++this.retryAttempts; // eslint-disable-next-line @typescript-eslint/naming-convention @@ -109,15 +112,15 @@ export class ToDeviceMessageQueue { // the scheduler function doesn't differentiate between fatal errors and just getting // bored and giving up for now if (Math.floor((e).httpStatus! / 100) === 4) { - logger.error("Fatal error when sending to-device message - dropping to-device batch!", e); + this.logger.error("Fatal error when sending to-device message - dropping to-device batch!", e); await this.client.store.removeToDeviceBatch(headBatch!.id); } else { - logger.info("Automatic retry limit reached for to-device messages."); + this.logger.info("Automatic retry limit reached for to-device messages."); } return; } - logger.info(`Failed to send batch of to-device messages. Will retry in ${retryDelay}ms`, e); + this.logger.info(`Failed to send batch of to-device messages. Will retry in ${retryDelay}ms`, e); this.retryTimeout = setTimeout(this.sendQueue, retryDelay); } finally { this.sending = false; @@ -133,7 +136,7 @@ export class ToDeviceMessageQueue { contentMap.getOrCreate(item.userId).set(item.deviceId, item.payload); } - logger.info( + this.logger.info( `Sending batch of ${batch.batch.length} to-device messages with ID ${batch.id} and txnId ${batch.txnId}`, ); @@ -146,7 +149,7 @@ export class ToDeviceMessageQueue { */ private onResumedSync = (state: SyncState | null, oldState: SyncState | null): void => { if (state === SyncState.Syncing && oldState !== SyncState.Syncing) { - logger.info(`Resuming queue after resumed sync`); + this.logger.info(`Resuming queue after resumed sync`); this.sendQueue(); } }; diff --git a/src/client.ts b/src/client.ts index 698079b99..bee940028 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1364,7 +1364,7 @@ export class MatrixClient extends TypedEventEmitter, @@ -276,11 +278,17 @@ export class PushProcessor { * Rewrites conditions on a client's push rules to match the defaults * where applicable. Useful for upgrading push rules to more strict * conditions when the server is falling behind on defaults. + * + * @param logger - A `Logger` to write log messages to. * @param incomingRules - The client's existing push rules * @param userId - The Matrix ID of the client. * @returns The rewritten rules */ - public static rewriteDefaultRules(incomingRules: IPushRules, userId: string | undefined = undefined): IPushRules { + public static rewriteDefaultRules( + logger: Logger, + incomingRules: IPushRules, + userId: string | undefined = undefined, + ): IPushRules { let newRules: IPushRules = JSON.parse(JSON.stringify(incomingRules)); // deep clone // These lines are mostly to make the tests happy. We shouldn't run into these @@ -292,6 +300,7 @@ export class PushProcessor { // Merge the client-level defaults with the ones from the server newRules.global.override = mergeRulesWithDefaults( + logger, PushRuleKind.Override, newRules.global.override, DEFAULT_OVERRIDE_RULES, @@ -299,6 +308,7 @@ export class PushProcessor { ); newRules.global.underride = mergeRulesWithDefaults( + logger, PushRuleKind.Underride, newRules.global.underride, DEFAULT_UNDERRIDE_RULES, diff --git a/src/serverCapabilities.ts b/src/serverCapabilities.ts index 5627aa4b1..3d3387fe4 100644 --- a/src/serverCapabilities.ts +++ b/src/serverCapabilities.ts @@ -15,7 +15,7 @@ limitations under the License. */ import { type IHttpOpts, type MatrixHttpApi, Method } from "./http-api/index.ts"; -import { logger } from "./logger.ts"; +import { type Logger } from "./logger.ts"; // How often we update the server capabilities. // 6 hours - an arbitrary value, but they should change very infrequently. @@ -78,7 +78,10 @@ export class ServerCapabilities { private retryTimeout?: ReturnType; private refreshTimeout?: ReturnType; - public constructor(private readonly http: MatrixHttpApi) {} + public constructor( + private readonly logger: Logger, + private readonly http: MatrixHttpApi, + ) {} /** * Starts periodically fetching the server capabilities. @@ -117,12 +120,12 @@ export class ServerCapabilities { await this.fetchCapabilities(); this.clearTimeouts(); this.refreshTimeout = setTimeout(this.poll, CAPABILITIES_CACHE_MS); - logger.debug("Fetched new server capabilities"); + this.logger.debug("Fetched new server capabilities"); } catch (e) { this.clearTimeouts(); const howLong = Math.floor(CAPABILITIES_RETRY_MS + Math.random() * 5000); this.retryTimeout = setTimeout(this.poll, howLong); - logger.warn(`Failed to refresh capabilities: retrying in ${howLong}ms`, e); + this.logger.warn(`Failed to refresh capabilities: retrying in ${howLong}ms`, e); } }; diff --git a/src/sliding-sync-sdk.ts b/src/sliding-sync-sdk.ts index 0bae2b640..21f16833a 100644 --- a/src/sliding-sync-sdk.ts +++ b/src/sliding-sync-sdk.ts @@ -326,8 +326,8 @@ export class SlidingSyncSdk { public constructor( private readonly slidingSync: SlidingSync, private readonly client: MatrixClient, - opts?: IStoredClientOpts, - syncOpts?: SyncApiOptions, + opts: IStoredClientOpts | undefined, + syncOpts: SyncApiOptions, ) { this.opts = defaultClientOpts(opts); this.syncOpts = defaultSyncApiOpts(syncOpts); @@ -356,7 +356,11 @@ export class SlidingSyncSdk { let room = this.client.store.getRoom(roomId); if (!room) { if (!roomData.initial) { - logger.debug("initial flag not set but no stored room exists for room ", roomId, roomData); + this.syncOpts.logger.debug( + "initial flag not set but no stored room exists for room ", + roomId, + roomData, + ); return; } room = _createAndReEmitRoom(this.client, roomId, this.opts); @@ -366,7 +370,7 @@ export class SlidingSyncSdk { private onLifecycle(state: SlidingSyncState, resp: MSC3575SlidingSyncResponse | null, err?: Error): void { if (err) { - logger.debug("onLifecycle", state, err); + this.syncOpts.logger.debug("onLifecycle", state, err); } switch (state) { case SlidingSyncState.Complete: @@ -407,7 +411,9 @@ export class SlidingSyncSdk { } } else { this.failCount = 0; - logger.log(`SlidingSyncState.RequestFinished with ${Object.keys(resp?.rooms || []).length} rooms`); + this.syncOpts.logger.debug( + `SlidingSyncState.RequestFinished with ${Object.keys(resp?.rooms || []).length} rooms`, + ); } break; } @@ -526,7 +532,7 @@ export class SlidingSyncSdk { private shouldAbortSync(error: MatrixError): boolean { if (error.errcode === "M_UNKNOWN_TOKEN") { // The logout already happened, we just need to stop. - logger.warn("Token no longer valid - assuming logout"); + this.syncOpts.logger.warn("Token no longer valid - assuming logout"); this.stop(); this.updateSyncState(SyncState.Error, { error }); return true; @@ -654,7 +660,7 @@ export class SlidingSyncSdk { for (let i = timelineEvents.length - 1; i >= 0; i--) { const eventId = timelineEvents[i].getId(); if (room.getTimelineForEvent(eventId)) { - logger.debug("Already have event " + eventId + " in limited " + + this.syncOpts.logger.debug("Already have event " + eventId + " in limited " + "sync - not resetting"); limited = false; @@ -863,19 +869,19 @@ export class SlidingSyncSdk { * Main entry point. Blocks until stop() is called. */ public async sync(): Promise { - logger.debug("Sliding sync init loop"); + this.syncOpts.logger.debug("Sliding sync init loop"); // 1) We need to get push rules so we can check if events should bing as we get // them from /sync. while (!this.client.isGuest()) { try { - logger.debug("Getting push rules..."); + this.syncOpts.logger.debug("Getting push rules..."); const result = await this.client.getPushRules(); - logger.debug("Got push rules"); + this.syncOpts.logger.debug("Got push rules"); this.client.pushRules = result; break; } catch (err) { - logger.error("Getting push rules failed", err); + this.syncOpts.logger.error("Getting push rules failed", err); if (this.shouldAbortSync(err)) { return; } @@ -890,7 +896,7 @@ export class SlidingSyncSdk { * Stops the sync object from syncing. */ public stop(): void { - logger.debug("SyncApi.stop"); + this.syncOpts.logger.debug("SyncApi.stop"); this.slidingSync.stop(); } diff --git a/src/sync.ts b/src/sync.ts index 01b9b8bb6..4509b6923 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -31,7 +31,7 @@ import { NotificationCountType, Room, RoomEvent } from "./models/room.ts"; import { deepCopy, noUnsafeEventProps, promiseMapSeries, unsafeProp } from "./utils.ts"; import { Filter } from "./filter.ts"; import { EventTimeline } from "./models/event-timeline.ts"; -import { logger } from "./logger.ts"; +import { type Logger } from "./logger.ts"; import { ClientEvent, type IStoredClientOpts, @@ -68,8 +68,6 @@ import { UNREAD_THREAD_NOTIFICATIONS } from "./@types/sync.ts"; import { Feature, ServerSupport } from "./feature.ts"; import { KnownMembership } from "./@types/membership.ts"; -const DEBUG = true; - // /sync requests allow you to set a timeout= but the request may continue // beyond that and wedge forever, so we need to track how long we are willing // to keep open the connection. This constant is *ADDED* to the timeout= value @@ -112,12 +110,6 @@ function getFilterName(userId: string, suffix?: string): string { return `FILTER_SYNC_${userId}` + (suffix ? "_" + suffix : ""); } -/* istanbul ignore next */ -function debuglog(...params: any[]): void { - if (!DEBUG) return; - logger.log(...params); -} - /** * Options passed into the constructor of SyncApi by MatrixClient */ @@ -134,6 +126,9 @@ export interface SyncApiOptions { * there are other references to the timelines for this room. */ canResetEntireTimeline?: ResetTimelineCallback; + + /** Logger instance to use for writing debug logs. */ + logger: Logger; } interface ISyncOptions { @@ -202,7 +197,7 @@ export function defaultClientOpts(opts?: IStoredClientOpts): IStoredClientOpts { }; } -export function defaultSyncApiOpts(syncOpts?: SyncApiOptions): SyncApiOptions { +export function defaultSyncApiOpts(syncOpts: SyncApiOptions): SyncApiOptions { return { canResetEntireTimeline: (_roomId): boolean => false, ...syncOpts, @@ -236,8 +231,8 @@ export class SyncApi { */ public constructor( private readonly client: MatrixClient, - opts?: IStoredClientOpts, - syncOpts?: SyncApiOptions, + opts: IStoredClientOpts | undefined, + syncOpts: SyncApiOptions, ) { this.opts = defaultClientOpts(opts); this.syncOpts = defaultSyncApiOpts(syncOpts); @@ -277,7 +272,7 @@ export class SyncApi { // 2. If it's from the first state we're seeing after joining the room // 3. Or whether it's coming from `syncFromCache` if (timelineWasEmpty) { - logger.debug( + this.syncOpts.logger.debug( `MarkerState: Ignoring markerEventId=${markerEvent.getId()} in roomId=${room.roomId} ` + `because the timeline was empty before the marker arrived which means there is nothing to refresh.`, ); @@ -309,14 +304,14 @@ export class SyncApi { if (isValidMsc2716Event) { // Saw new marker event, let's let the clients know they should // refresh the timeline. - logger.debug( + this.syncOpts.logger.debug( `MarkerState: Timeline needs to be refreshed because ` + `a new markerEventId=${markerEvent.getId()} was sent in roomId=${room.roomId}`, ); room.setTimelineNeedsRefresh(true); room.emit(RoomEvent.HistoryImportedWithinTimeline, markerEvent, room); } else { - logger.debug( + this.syncOpts.logger.debug( `MarkerState: Ignoring markerEventId=${markerEvent.getId()} in roomId=${room.roomId} because ` + `MSC2716 is not supported in the room version or for any room version, the marker wasn't sent ` + `by the room creator.`, @@ -489,7 +484,7 @@ export class SyncApi { */ private peekPoll(peekRoom: Room, token?: string): void { if (this._peekRoom !== peekRoom) { - debuglog("Stopped peeking in room %s", peekRoom.roomId); + this.syncOpts.logger.debug("Stopped peeking in room %s", peekRoom.roomId); return; } @@ -512,7 +507,7 @@ export class SyncApi { .then( async (res) => { if (this._peekRoom !== peekRoom) { - debuglog("Stopped peeking in room %s", peekRoom.roomId); + this.syncOpts.logger.debug("Stopped peeking in room %s", peekRoom.roomId); return; } // We have a problem that we get presence both from /events and /sync @@ -554,7 +549,7 @@ export class SyncApi { this.peekPoll(peekRoom, res.end); }, (err) => { - logger.error("[%s] Peek poll failed: %s", peekRoom.roomId, err); + this.syncOpts.logger.error("[%s] Peek poll failed: %s", peekRoom.roomId, err); setTimeout(() => { this.peekPoll(peekRoom, token); }, 30 * 1000); @@ -595,7 +590,7 @@ export class SyncApi { private shouldAbortSync(error: MatrixError): boolean { if (error.errcode === "M_UNKNOWN_TOKEN") { // The logout already happened, we just need to stop. - logger.warn("Token no longer valid - assuming logout"); + this.syncOpts.logger.warn("Token no longer valid - assuming logout"); this.stop(); this.updateSyncState(SyncState.Error, { error }); return true; @@ -605,17 +600,17 @@ export class SyncApi { private getPushRules = async (): Promise => { try { - debuglog("Getting push rules..."); + this.syncOpts.logger.debug("Getting push rules..."); const result = await this.client.getPushRules(); - debuglog("Got push rules"); + this.syncOpts.logger.debug("Got push rules"); this.client.pushRules = result; } catch (err) { - logger.error("Getting push rules failed", err); + this.syncOpts.logger.error("Getting push rules failed", err); if (this.shouldAbortSync(err)) return; // wait for saved sync to complete before doing anything else, // otherwise the sync state will end up being incorrect - debuglog("Waiting for saved sync before retrying push rules..."); + this.syncOpts.logger.debug("Waiting for saved sync before retrying push rules..."); await this.recoverFromSyncStartupError(this.savedSyncPromise, err); return this.getPushRules(); // try again } @@ -630,12 +625,12 @@ export class SyncApi { }; private prepareLazyLoadingForSync = async (): Promise => { - debuglog("Prepare lazy loading for sync..."); + this.syncOpts.logger.debug("Prepare lazy loading for sync..."); if (this.client.isGuest()) { this.opts.lazyLoadMembers = false; } if (this.opts.lazyLoadMembers) { - debuglog("Enabling lazy load on sync filter..."); + this.syncOpts.logger.debug("Enabling lazy load on sync filter..."); if (!this.opts.filter) { this.opts.filter = this.buildDefaultFilter(); } @@ -645,11 +640,11 @@ export class SyncApi { private storeClientOptions = async (): Promise => { try { - debuglog("Storing client options..."); + this.syncOpts.logger.debug("Storing client options..."); await this.client.storeClientOptions(); - debuglog("Stored client options"); + this.syncOpts.logger.debug("Stored client options"); } catch (err) { - logger.error("Storing client options failed", err); + this.syncOpts.logger.error("Storing client options failed", err); throw err; } }; @@ -658,7 +653,7 @@ export class SyncApi { filterId?: string; filter?: Filter; }> => { - debuglog("Getting filter..."); + this.syncOpts.logger.debug("Getting filter..."); let filter: Filter; if (this.opts.filter) { filter = this.opts.filter; @@ -670,11 +665,11 @@ export class SyncApi { try { filterId = await this.client.getOrCreateFilter(getFilterName(this.client.credentials.userId!), filter); } catch (err) { - logger.error("Getting filter failed", err); + this.syncOpts.logger.error("Getting filter failed", err); if (this.shouldAbortSync(err)) return {}; // wait for saved sync to complete before doing anything else, // otherwise the sync state will end up being incorrect - debuglog("Waiting for saved sync before retrying filter..."); + this.syncOpts.logger.debug("Waiting for saved sync before retrying filter..."); await this.recoverFromSyncStartupError(this.savedSyncPromise, err); return this.getFilter(); // try again } @@ -700,22 +695,22 @@ export class SyncApi { // Pull the saved sync token out first, before the worker starts sending // all the sync data which could take a while. This will let us send our // first incremental sync request before we've processed our saved data. - debuglog("Getting saved sync token..."); + this.syncOpts.logger.debug("Getting saved sync token..."); const savedSyncTokenPromise = this.client.store.getSavedSyncToken().then((tok) => { - debuglog("Got saved sync token"); + this.syncOpts.logger.debug("Got saved sync token"); return tok; }); this.savedSyncPromise = this.client.store .getSavedSync() .then((savedSync) => { - debuglog(`Got reply from saved sync, exists? ${!!savedSync}`); + this.syncOpts.logger.debug(`Got reply from saved sync, exists? ${!!savedSync}`); if (savedSync) { return this.syncFromCache(savedSync); } }) .catch((err) => { - logger.error("Getting saved sync failed", err); + this.syncOpts.logger.error("Getting saved sync failed", err); }); // We need to do one-off checks before we can begin the /sync loop. @@ -747,9 +742,9 @@ export class SyncApi { const savedSyncToken = await savedSyncTokenPromise; if (savedSyncToken) { - debuglog("Sending first sync request..."); + this.syncOpts.logger.debug("Sending first sync request..."); } else { - debuglog("Sending initial sync request..."); + this.syncOpts.logger.debug("Sending initial sync request..."); const initialFilter = this.buildDefaultFilter(); initialFilter.setDefinition(filter.getDefinition()); initialFilter.setTimelineLimit(this.opts.initialSyncLimit!); @@ -763,7 +758,7 @@ export class SyncApi { } // Now wait for the saved sync to finish... - debuglog("Waiting for saved sync before starting sync processing..."); + this.syncOpts.logger.debug("Waiting for saved sync before starting sync processing..."); await this.savedSyncPromise; // process the first sync request and continue syncing with the normal filterId return this.doSync({ filter: filterId }); @@ -773,7 +768,7 @@ export class SyncApi { * Stops the sync object from syncing. */ public stop(): void { - debuglog("SyncApi.stop"); + this.syncOpts.logger.debug("SyncApi.stop"); // It is necessary to check for the existance of // globalThis.window AND globalThis.window.removeEventListener. // Some platforms (e.g. React Native) register globalThis.window, @@ -805,7 +800,7 @@ export class SyncApi { * should have been acquired via client.store.getSavedSync(). */ private async syncFromCache(savedSync: ISavedSync): Promise { - debuglog("sync(): not doing HTTP hit, instead returning stored /sync data"); + this.syncOpts.logger.debug("sync(): not doing HTTP hit, instead returning stored /sync data"); const nextSyncToken = savedSync.nextBatch; @@ -830,7 +825,7 @@ export class SyncApi { try { await this.processSyncResponse(syncEventData, data); } catch (e) { - logger.error("Error processing cached sync", e); + this.syncOpts.logger.error("Error processing cached sync", e); } // Don't emit a prepared if we've bailed because the store is invalid: @@ -881,7 +876,7 @@ export class SyncApi { } catch (e) { // log the exception with stack if we have it, else fall back // to the plain description - logger.error("Caught /sync error", e); + this.syncOpts.logger.error("Caught /sync error", e); // Emit the exception for client handling this.client.emit(ClientEvent.SyncUnexpectedError, e); @@ -916,7 +911,7 @@ export class SyncApi { } if (!this.running) { - debuglog("Sync no longer running: exiting."); + this.syncOpts.logger.debug("Sync no longer running: exiting."); if (this.connectionReturnedResolvers) { this.connectionReturnedResolvers.reject(); this.connectionReturnedResolvers = undefined; @@ -999,7 +994,7 @@ export class SyncApi { private async onSyncError(err: MatrixError): Promise { if (!this.running) { - debuglog("Sync no longer running: exiting"); + this.syncOpts.logger.debug("Sync no longer running: exiting"); if (this.connectionReturnedResolvers) { this.connectionReturnedResolvers.reject(); this.connectionReturnedResolvers = undefined; @@ -1008,16 +1003,16 @@ export class SyncApi { return true; // abort } - logger.error("/sync error %s", err); + this.syncOpts.logger.error("/sync error %s", err); if (this.shouldAbortSync(err)) { return true; // abort } this.failedSyncCount++; - logger.log("Number of consecutive failed sync requests:", this.failedSyncCount); + this.syncOpts.logger.debug("Number of consecutive failed sync requests:", this.failedSyncCount); - debuglog("Starting keep-alive"); + this.syncOpts.logger.debug("Starting keep-alive"); // Note that we do *not* mark the sync connection as // lost yet: we only do this if a keepalive poke // fails, since long lived HTTP connections will @@ -1324,7 +1319,7 @@ export class SyncApi { for (let i = timelineEvents.length - 1; i >= 0; i--) { const eventId = timelineEvents[i].getId()!; if (room.getTimelineForEvent(eventId)) { - debuglog(`Already have event ${eventId} in limited sync - not resetting`); + this.syncOpts.logger.debug(`Already have event ${eventId} in limited sync - not resetting`); limited = false; // we might still be missing some of the events before i; @@ -1384,7 +1379,7 @@ export class SyncApi { await this.injectRoomEvents(room, stateEvents, undefined, timelineEvents, syncEventData.fromCache); } } catch (e) { - logger.error(`Failed to process events on room ${room.roomId}:`, e); + this.syncOpts.logger.error(`Failed to process events on room ${room.roomId}:`, e); } // set summary after processing events, @@ -1865,7 +1860,7 @@ export class SyncApi { * but this might help us reconnect a little faster. */ private onOnline = (): void => { - debuglog("Browser thinks we are back online"); + this.syncOpts.logger.debug("Browser thinks we are back online"); this.startKeepAlives(0); }; }