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

Open
wants to merge 1 commit into
base: livekit
Choose a base branch
from

Conversation

hughns
Copy link
Member

@hughns hughns commented Sep 11, 2024

No description provided.

Comment on lines +481 to +489
(
["trace", "debug", "info", "warn", "error"] as (
| "trace"
| "debug"
| "info"
| "warn"
| "error"
)[]
).forEach((level) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly less nasty:

Suggested change
(
["trace", "debug", "info", "warn", "error"] as (
| "trace"
| "debug"
| "info"
| "warn"
| "error"
)[]
).forEach((level) => {
[
"trace" as const,
"debug" as const,
"info" as const,
"warn" as const,
"error" as const,
].forEach((level) => {

And thank https://typescript-eslint.io/rules/prefer-as-const/ for teaching me about "as const" 😃

Comment on lines +490 to +492
if (!window.console[level]) return;
const prefix = `${level.toUpperCase()} matrix_sdk`;
const originalMethod = window.console[level];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, rearrange some lines to avoid a redundant lookup on window.console

Suggested change
if (!window.console[level]) return;
const prefix = `${level.toUpperCase()} matrix_sdk`;
const originalMethod = window.console[level];
const originalMethod = window.console[level];
if (!originalMethod) return;
const prefix = `${level.toUpperCase()} matrix_sdk`;

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is passing the entire args array intentional, or should args[0] (i.e. the argument with the prefix) be excluded?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants