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

Rageshake logging improvements #2622

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { logger } from "matrix-js-sdk/src/logger";
import {
setLogExtension as setLKLogExtension,
setLogLevel,
setLogLevel as setLKLogLevel,
} from "livekit-client";

import { App } from "./App";
Expand All @@ -28,9 +28,11 @@
initRageshake().catch((e) => {
logger.error("Failed to initialize rageshake", e);
});

setLogLevel("debug");
setLKLogExtension(global.mx_rage_logger.log);
setLKLogLevel("debug");
setLKLogExtension((level, msg, context) => {

Check warning on line 32 in src/main.tsx

View check run for this annotation

Codecov / codecov/patch

src/main.tsx#L31-L32

Added lines #L31 - L32 were not covered by tests
// we pass a synthetic logger name of "livekit" to the rageshake to make it easier to read
global.mx_rage_logger.log(level, "livekit", msg, context);
});

Check warning on line 35 in src/main.tsx

View check run for this annotation

Codecov / codecov/patch

src/main.tsx#L34-L35

Added lines #L34 - L35 were not covered by tests

logger.info(`Element Call ${import.meta.env.VITE_APP_VERSION || "dev"}`);

Expand Down
30 changes: 21 additions & 9 deletions src/settings/rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

import EventEmitter from "events";
import { throttle } from "lodash";
import { logger } from "matrix-js-sdk/src/logger";
import { Logger, logger } from "matrix-js-sdk/src/logger";
import { randomString } from "matrix-js-sdk/src/randomstring";
import { LoggingMethod } from "loglevel";
import loglevel, { LoggingMethod } from "loglevel";

// the length of log data we keep in indexeddb (and include in the reports)
const MAX_LOG_SIZE = 1024 * 1024 * 5; // 5 MB
Expand Down Expand Up @@ -467,7 +467,12 @@
*/
export async function init(): Promise<void> {
global.mx_rage_logger = new ConsoleLogger();
setLogExtension(global.mx_rage_logger.log);
setLogExtension(logger, global.mx_rage_logger.log);

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

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L470

Added line #L470 was not covered by tests
// 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);
});

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

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L473-L475

Added lines #L473 - L475 were not covered by tests

return tryInitStorage();
}
Expand Down Expand Up @@ -580,10 +585,14 @@
* took loglevel's example honouring log levels). Adds a loglevel logging extension
* in the recommended way.
*/
export function setLogExtension(extension: LogExtensionFunc): void {
const originalFactory = logger.methodFactory;

logger.methodFactory = function (
function setLogExtension(
_loggerToExtend: Logger,
extension: LogExtensionFunc,
): void {
const loggerToExtend = _loggerToExtend as unknown as loglevel.Logger;
const originalFactory = loggerToExtend.methodFactory;

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

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L588-L593

Added lines #L588 - L593 were not covered by tests

loggerToExtend.methodFactory = function (

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

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L595

Added line #L595 was not covered by tests
methodName,
configLevel,
loggerName,
Expand All @@ -594,11 +603,14 @@
const needLog = logLevel >= configLevel && logLevel < LogLevel.silent;

return (...args) => {
// we don't send the logger name to the raw method as some of them are already outputting the prefix
rawMethod.apply(this, args);
if (needLog) {
extension(logLevel, ...args);
// we prefix the logger name to the extension
// this makes sure that the rageshake contains the logger name
extension(logLevel, loggerName?.toString(), ...args);

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

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L611

Added line #L611 was not covered by tests
}
};
};
logger.setLevel(logger.getLevel()); // Be sure to call setLevel method in order to apply plugin
loggerToExtend.setLevel(loggerToExtend.getLevel()); // Be sure to call setLevel method in order to apply plugin

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

View check run for this annotation

Codecov / codecov/patch

src/settings/rageshake.ts#L615

Added line #L615 was not covered by tests
}