Skip to content

Commit 8152fa4

Browse files
committed
Add more logging scopes to session IDs
This uses prefix chaining to correlate several scopes together.
1 parent e217bf9 commit 8152fa4

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/crypto/OlmDevice.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,14 @@ OlmDevice.prototype.getSessionIdsForDevice = async function(theirDeviceIdentityK
656656
* @param {boolean} nowait Don't wait for an in-progress session to complete.
657657
* This should only be set to true of the calling function is the function
658658
* that marked the session as being in-progress.
659+
* @param {Logger} [log] A possibly customised log
659660
* @return {Promise<?string>} session id, or null if no established session
660661
*/
661662
OlmDevice.prototype.getSessionIdForDevice = async function(
662-
theirDeviceIdentityKey, nowait,
663+
theirDeviceIdentityKey, nowait, log,
663664
) {
664665
const sessionInfos = await this.getSessionInfoForDevice(
665-
theirDeviceIdentityKey, nowait,
666+
theirDeviceIdentityKey, nowait, log,
666667
);
667668

668669
if (sessionInfos.length === 0) {
@@ -702,10 +703,13 @@ OlmDevice.prototype.getSessionIdForDevice = async function(
702703
* @param {boolean} nowait Don't wait for an in-progress session to complete.
703704
* This should only be set to true of the calling function is the function
704705
* that marked the session as being in-progress.
706+
* @param {Logger} [log] A possibly customised log
705707
* @return {Array.<{sessionId: string, hasReceivedMessage: Boolean}>}
706708
*/
707-
OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey, nowait) {
708-
const log = logger.withPrefix("[getSessionInfoForDevice]");
709+
OlmDevice.prototype.getSessionInfoForDevice = async function(
710+
deviceIdentityKey, nowait, log = logger,
711+
) {
712+
log = log.withPrefix("[getSessionInfoForDevice]");
709713

710714
if (this._sessionsInProgress[deviceIdentityKey] && !nowait) {
711715
log.debug(`Waiting for Olm session for ${deviceIdentityKey} to be created`);

src/crypto/olmlib.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export async function getExistingOlmSessions(
183183
* @param {Array} [failedServers] An array to fill with remote servers that
184184
* failed to respond to one-time-key requests.
185185
*
186-
* @param {Object} [log] A possibly customised log
186+
* @param {Logger} [log] A possibly customised log
187187
*
188188
* @return {Promise} resolves once the sessions are complete, to
189189
* an Object mapping from userId to deviceId to
@@ -257,7 +257,7 @@ export async function ensureOlmSessionsForDevices(
257257
);
258258
}
259259
const sessionId = await olmDevice.getSessionIdForDevice(
260-
key, resolveSession[key],
260+
key, resolveSession[key], log,
261261
);
262262
log.debug(`Got Olm session ${sessionId} ${forWhom}`);
263263
if (sessionId !== null && resolveSession[key]) {

src/crypto/store/indexeddb-crypto-store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ export class IndexedDBCryptoStore {
596596
* @param {function(*)} func Function called with the
597597
* transaction object: an opaque object that should be passed
598598
* to store functions.
599-
* @param {object} [log] A possibly customised log
599+
* @param {Logger} [log] A possibly customised log
600600
* @return {Promise} Promise that resolves with the result of the `func`
601601
* when the transaction is complete. If the backend is
602602
* async (ie. the indexeddb backend) any of the callback

src/logger.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ interface PrefixedLogger extends Logger {
6868
}
6969

7070
function extendLogger(logger: PrefixedLogger) {
71-
logger.withPrefix = function(prefix: string) {
72-
return getPrefixedLogger(this.prefix + prefix);
71+
logger.withPrefix = function(prefix: string): PrefixedLogger {
72+
const existingPrefix = this.prefix || "";
73+
return getPrefixedLogger(existingPrefix + prefix);
7374
};
7475
}
7576

0 commit comments

Comments
 (0)