Skip to content

Commit

Permalink
Intercept matrix_sdk logging via console and include in rageshake (#2623
Browse files Browse the repository at this point in the history
)

Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
  • Loading branch information
hughns and AndrewFerr authored Sep 23, 2024
1 parent d089ff6 commit d14b434
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/settings/rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,38 @@ declare global {
*/
export async function init(): Promise<void> {
global.mx_rage_logger = new ConsoleLogger();

// configure loglevel based loggers:
setLogExtension(logger, global.mx_rage_logger.log);
// these are the child/prefixed loggers we want to capture from js-sdk
// there doesn't seem to be an easy way to capture all children
["MatrixRTCSession", "MatrixRTCSessionManager"].forEach((loggerName) => {
setLogExtension(logger.getChild(loggerName), global.mx_rage_logger.log);
});

// intercept console logging so that we can get matrix_sdk logs:
// this is nasty, but no logging hooks are provided
[
"trace" as const,
"debug" as const,
"info" as const,
"warn" as const,
"error" as const,
].forEach((level) => {
const originalMethod = window.console[level];
if (!originalMethod) return;
const prefix = `${level.toUpperCase()} matrix_sdk`;
window.console[level] = (...args): void => {
originalMethod(...args);
// args for calls from the matrix-sdk-crypto-wasm look like:
// ["DEBUG matrix_sdk_indexeddb::crypto_store: IndexedDbCryptoStore: opening main store matrix-js-sdk::matrix-sdk-crypto\n at /home/runner/.cargo/git/checkouts/matrix-rust-sdk-1f4927f82a3d27bb/07aa6d7/crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs:267"]
if (typeof args[0] === "string" && args[0].startsWith(prefix)) {
// we pass all the args on to the logger in case there are more sent in future
global.mx_rage_logger.log(LogLevel[level], "matrix_sdk", ...args);
}
};
});

return tryInitStorage();
}

Expand Down

0 comments on commit d14b434

Please sign in to comment.