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 1 commit
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
24 changes: 24 additions & 0 deletions src/settings/rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,37 @@
*/
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", "debug", "info", "warn", "error"] as (

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

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L481-L482

Added lines #L481 - L482 were not covered by tests
| "trace"
| "debug"
| "info"
| "warn"
| "error"
)[]
).forEach((level) => {
hughns marked this conversation as resolved.
Show resolved Hide resolved
if (!window.console[level]) return;
const prefix = `${level.toUpperCase()} matrix_sdk`;
const originalMethod = window.console[level];
hughns marked this conversation as resolved.
Show resolved Hide resolved
window.console[level] = (...args): void => {
originalMethod(...args);
if (typeof args[0] === "string" && args[0].startsWith(prefix)) {
global.mx_rage_logger.log(LogLevel[level], "matrix_sdk", ...args);
hughns marked this conversation as resolved.
Show resolved Hide resolved
}
};
});

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

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L489-L499

Added lines #L489 - L499 were not covered by tests

return tryInitStorage();
}

Expand Down