Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercept matrix_sdk logging via console and include in rageshake #2623

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
*/
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);

Check warning on line 492 in src/settings/rageshake.ts

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L481-L492

Added lines #L481 - L492 were not covered by tests
// 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)) {

Check warning on line 495 in src/settings/rageshake.ts

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L495

Added line #L495 was not covered by tests
// 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);
hughns marked this conversation as resolved.
Show resolved Hide resolved
}
};
});

Check warning on line 500 in src/settings/rageshake.ts

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L497-L500

Added lines #L497 - L500 were not covered by tests

return tryInitStorage();
}

Expand Down