@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
1616limitations under the License.
1717*/
1818
19- import { getPrefixedLogger , logger } from '../logger' ;
19+ import { logger } from '../logger' ;
2020import { IndexedDBCryptoStore } from './store/indexeddb-crypto-store' ;
2121import * as algorithms from './algorithms' ;
2222
@@ -545,7 +545,7 @@ OlmDevice.prototype.createOutboundSession = async function(
545545 }
546546 } ) ;
547547 } ,
548- getPrefixedLogger ( "[createOutboundSession]" ) ,
548+ logger . withPrefix ( "[createOutboundSession]" ) ,
549549 ) ;
550550 return newSessionId ;
551551} ;
@@ -606,7 +606,7 @@ OlmDevice.prototype.createInboundSession = async function(
606606 }
607607 } ) ;
608608 } ,
609- getPrefixedLogger ( "[createInboundSession]" ) ,
609+ logger . withPrefix ( "[createInboundSession]" ) ,
610610 ) ;
611611
612612 return result ;
@@ -621,8 +621,10 @@ OlmDevice.prototype.createInboundSession = async function(
621621 * @return {Promise<string[]> } a list of known session ids for the device
622622 */
623623OlmDevice . prototype . getSessionIdsForDevice = async function ( theirDeviceIdentityKey ) {
624+ const log = logger . withPrefix ( "[getSessionIdsForDevice]" ) ;
625+
624626 if ( this . _sessionsInProgress [ theirDeviceIdentityKey ] ) {
625- logger . log ( "waiting for olm session to be created" ) ;
627+ log . debug ( `Waiting for Olm session for ${ theirDeviceIdentityKey } to be created` ) ;
626628 try {
627629 await this . _sessionsInProgress [ theirDeviceIdentityKey ] ;
628630 } catch ( e ) {
@@ -640,7 +642,7 @@ OlmDevice.prototype.getSessionIdsForDevice = async function(theirDeviceIdentityK
640642 } ,
641643 ) ;
642644 } ,
643- getPrefixedLogger ( "[getSessionIdsForDevice]" ) ,
645+ log ,
644646 ) ;
645647
646648 return sessionIds ;
@@ -654,13 +656,14 @@ OlmDevice.prototype.getSessionIdsForDevice = async function(theirDeviceIdentityK
654656 * @param {boolean } nowait Don't wait for an in-progress session to complete.
655657 * This should only be set to true of the calling function is the function
656658 * that marked the session as being in-progress.
659+ * @param {Logger } [log] A possibly customised log
657660 * @return {Promise<?string> } session id, or null if no established session
658661 */
659662OlmDevice . prototype . getSessionIdForDevice = async function (
660- theirDeviceIdentityKey , nowait ,
663+ theirDeviceIdentityKey , nowait , log ,
661664) {
662665 const sessionInfos = await this . getSessionInfoForDevice (
663- theirDeviceIdentityKey , nowait ,
666+ theirDeviceIdentityKey , nowait , log ,
664667 ) ;
665668
666669 if ( sessionInfos . length === 0 ) {
@@ -700,11 +703,16 @@ OlmDevice.prototype.getSessionIdForDevice = async function(
700703 * @param {boolean } nowait Don't wait for an in-progress session to complete.
701704 * This should only be set to true of the calling function is the function
702705 * that marked the session as being in-progress.
706+ * @param {Logger } [log] A possibly customised log
703707 * @return {Array.<{sessionId: string, hasReceivedMessage: Boolean}> }
704708 */
705- OlmDevice . prototype . getSessionInfoForDevice = async function ( deviceIdentityKey , nowait ) {
709+ OlmDevice . prototype . getSessionInfoForDevice = async function (
710+ deviceIdentityKey , nowait , log = logger ,
711+ ) {
712+ log = log . withPrefix ( "[getSessionInfoForDevice]" ) ;
713+
706714 if ( this . _sessionsInProgress [ deviceIdentityKey ] && ! nowait ) {
707- logger . log ( "waiting for olm session to be created" ) ;
715+ log . debug ( `Waiting for Olm session for ${ deviceIdentityKey } to be created` ) ;
708716 try {
709717 await this . _sessionsInProgress [ deviceIdentityKey ] ;
710718 } catch ( e ) {
@@ -730,7 +738,7 @@ OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey,
730738 }
731739 } ) ;
732740 } ,
733- getPrefixedLogger ( "[getSessionInfoForDevice]" ) ,
741+ log ,
734742 ) ;
735743
736744 return info ;
@@ -765,7 +773,7 @@ OlmDevice.prototype.encryptMessage = async function(
765773 this . _saveSession ( theirDeviceIdentityKey , sessionInfo , txn ) ;
766774 } ) ;
767775 } ,
768- getPrefixedLogger ( "[encryptMessage]" ) ,
776+ logger . withPrefix ( "[encryptMessage]" ) ,
769777 ) ;
770778 return res ;
771779} ;
@@ -799,7 +807,7 @@ OlmDevice.prototype.decryptMessage = async function(
799807 this . _saveSession ( theirDeviceIdentityKey , sessionInfo , txn ) ;
800808 } ) ;
801809 } ,
802- getPrefixedLogger ( "[decryptMessage]" ) ,
810+ logger . withPrefix ( "[decryptMessage]" ) ,
803811 ) ;
804812 return payloadString ;
805813} ;
@@ -831,7 +839,7 @@ OlmDevice.prototype.matchesSession = async function(
831839 matches = sessionInfo . session . matches_inbound ( ciphertext ) ;
832840 } ) ;
833841 } ,
834- getPrefixedLogger ( "[matchesSession]" ) ,
842+ logger . withPrefix ( "[matchesSession]" ) ,
835843 ) ;
836844 return matches ;
837845} ;
@@ -1102,7 +1110,7 @@ OlmDevice.prototype.addInboundGroupSession = async function(
11021110 } ,
11031111 ) ;
11041112 } ,
1105- getPrefixedLogger ( "[addInboundGroupSession]" ) ,
1113+ logger . withPrefix ( "[addInboundGroupSession]" ) ,
11061114 ) ;
11071115} ;
11081116
@@ -1273,7 +1281,7 @@ OlmDevice.prototype.decryptGroupMessage = async function(
12731281 } ,
12741282 ) ;
12751283 } ,
1276- getPrefixedLogger ( "[decryptGroupMessage]" ) ,
1284+ logger . withPrefix ( "[decryptGroupMessage]" ) ,
12771285 ) ;
12781286
12791287 if ( error ) {
@@ -1319,7 +1327,7 @@ OlmDevice.prototype.hasInboundSessionKeys = async function(roomId, senderKey, se
13191327 } ,
13201328 ) ;
13211329 } ,
1322- getPrefixedLogger ( "[hasInboundSessionKeys]" ) ,
1330+ logger . withPrefix ( "[hasInboundSessionKeys]" ) ,
13231331 ) ;
13241332
13251333 return result ;
@@ -1379,7 +1387,7 @@ OlmDevice.prototype.getInboundGroupSessionKey = async function(
13791387 } ,
13801388 ) ;
13811389 } ,
1382- getPrefixedLogger ( "[getInboundGroupSessionKey]" ) ,
1390+ logger . withPrefix ( "[getInboundGroupSessionKey]" ) ,
13831391 ) ;
13841392
13851393 return result ;
0 commit comments