mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 02:26:53 +00:00
Matrix-js: silence sdk debug logs in non-verbose verify
This commit is contained in:
@@ -4,8 +4,17 @@ let matrixSdkLoggingConfigured = false;
|
||||
let matrixSdkLogMode: "default" | "quiet" = "default";
|
||||
const matrixSdkBaseLogger = new ConsoleLogger();
|
||||
|
||||
type MatrixJsSdkLogger = {
|
||||
trace: (...messageOrObject: unknown[]) => void;
|
||||
debug: (...messageOrObject: unknown[]) => void;
|
||||
info: (...messageOrObject: unknown[]) => void;
|
||||
warn: (...messageOrObject: unknown[]) => void;
|
||||
error: (...messageOrObject: unknown[]) => void;
|
||||
getChild: (namespace: string) => MatrixJsSdkLogger;
|
||||
};
|
||||
|
||||
function shouldSuppressMatrixHttpNotFound(module: string, messageOrObject: unknown[]): boolean {
|
||||
if (module !== "MatrixHttpClient") {
|
||||
if (!module.includes("MatrixHttpClient")) {
|
||||
return false;
|
||||
}
|
||||
return messageOrObject.some((entry) => {
|
||||
@@ -31,6 +40,10 @@ export function setMatrixSdkLogMode(mode: "default" | "quiet"): void {
|
||||
applyMatrixSdkLogger();
|
||||
}
|
||||
|
||||
export function createMatrixJsSdkClientLogger(prefix = "matrix-js"): MatrixJsSdkLogger {
|
||||
return createMatrixJsSdkLoggerInstance(prefix);
|
||||
}
|
||||
|
||||
function applyMatrixSdkLogger(): void {
|
||||
if (matrixSdkLogMode === "quiet") {
|
||||
LogService.setLogger({
|
||||
@@ -56,3 +69,32 @@ function applyMatrixSdkLogger(): void {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function createMatrixJsSdkLoggerInstance(prefix: string): MatrixJsSdkLogger {
|
||||
const log = (method: keyof ConsoleLogger, ...messageOrObject: unknown[]): void => {
|
||||
if (matrixSdkLogMode === "quiet") {
|
||||
return;
|
||||
}
|
||||
(matrixSdkBaseLogger[method] as (module: string, ...args: unknown[]) => void)(
|
||||
prefix,
|
||||
...messageOrObject,
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
trace: (...messageOrObject) => log("trace", ...messageOrObject),
|
||||
debug: (...messageOrObject) => log("debug", ...messageOrObject),
|
||||
info: (...messageOrObject) => log("info", ...messageOrObject),
|
||||
warn: (...messageOrObject) => log("warn", ...messageOrObject),
|
||||
error: (...messageOrObject) => {
|
||||
if (shouldSuppressMatrixHttpNotFound(prefix, messageOrObject)) {
|
||||
return;
|
||||
}
|
||||
log("error", ...messageOrObject);
|
||||
},
|
||||
getChild: (namespace: string) => {
|
||||
const nextNamespace = namespace.trim();
|
||||
return createMatrixJsSdkLoggerInstance(nextNamespace ? `${prefix}.${nextNamespace}` : prefix);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -782,6 +782,17 @@ describe("MatrixClient crypto bootstrapping", () => {
|
||||
expect(Array.from(resolved?.[1] ?? [])).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
it("provides a matrix-js-sdk logger to createClient", () => {
|
||||
new MatrixClient("https://matrix.example.org", "token");
|
||||
const logger = (lastCreateClientOpts?.logger ?? null) as {
|
||||
debug?: (...args: unknown[]) => void;
|
||||
getChild?: (namespace: string) => unknown;
|
||||
} | null;
|
||||
expect(logger).not.toBeNull();
|
||||
expect(logger?.debug).toBeTypeOf("function");
|
||||
expect(logger?.getChild).toBeTypeOf("function");
|
||||
});
|
||||
|
||||
it("schedules periodic crypto snapshot persistence with fake timers", async () => {
|
||||
vi.useFakeTimers();
|
||||
const databasesSpy = vi.spyOn(indexedDB, "databases").mockResolvedValue([]);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type MatrixEvent,
|
||||
} from "matrix-js-sdk";
|
||||
import { VerificationMethod } from "matrix-js-sdk/lib/types.js";
|
||||
import { createMatrixJsSdkClientLogger } from "./client/logging.js";
|
||||
import { MatrixCryptoBootstrapper } from "./sdk/crypto-bootstrap.js";
|
||||
import type { MatrixCryptoBootstrapResult } from "./sdk/crypto-bootstrap.js";
|
||||
import { createMatrixCryptoFacade, type MatrixCryptoFacade } from "./sdk/crypto-facade.js";
|
||||
@@ -181,6 +182,7 @@ export class MatrixClient {
|
||||
accessToken,
|
||||
userId: opts.userId,
|
||||
deviceId: opts.deviceId,
|
||||
logger: createMatrixJsSdkClientLogger("MatrixClient"),
|
||||
localTimeoutMs: this.localTimeoutMs,
|
||||
cryptoCallbacks,
|
||||
verificationMethods: [
|
||||
|
||||
Reference in New Issue
Block a user