mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-30 00:50:48 +08:00
Intercept matrix_sdk logging via console
This commit is contained in:
parent
8e38d66611
commit
55ea373cd0
@ -467,6 +467,8 @@ 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
|
||||
@ -474,6 +476,28 @@ export async function init(): Promise<void> {
|
||||
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 (
|
||||
| "trace"
|
||||
| "debug"
|
||||
| "info"
|
||||
| "warn"
|
||||
| "error"
|
||||
)[]
|
||||
).forEach((level) => {
|
||||
if (!window.console[level]) return;
|
||||
const prefix = `${level.toUpperCase()} matrix_sdk`;
|
||||
const originalMethod = window.console[level];
|
||||
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);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return tryInitStorage();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user