You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Allow applications to specify their own logger instance (#3792)
* Support MatrixClient-specific loggers. Signed-off-by: Patrick Cloke <clokep@patrick.cloke.us> * Use client-specific logger in client.ts. Signed-off-by: Patrick Cloke <clokep@patrick.cloke.us> * Log `fetch` requests to the per-client logger * Use client-specific logger in rust-crypto
This commit is contained in:
committed by
GitHub
parent
7c2a12085c
commit
42be793a56
@@ -25,7 +25,6 @@ import { ConnectionError, MatrixError } from "./errors";
|
||||
import { HttpApiEvent, HttpApiEventHandlerMap, IHttpOpts, IRequestOpts, Body } from "./interface";
|
||||
import { anySignal, parseErrorResponse, timeoutSignal } from "./utils";
|
||||
import { QueryDict } from "../utils";
|
||||
import { logger } from "../logger";
|
||||
|
||||
interface TypedResponse<T> extends Response {
|
||||
json(): Promise<T>;
|
||||
@@ -225,7 +224,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
|
||||
opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "keepAlive" | "abortSignal" | "priority"> = {},
|
||||
): Promise<ResponseType<T, O>> {
|
||||
const urlForLogs = this.sanitizeUrlForLogs(url);
|
||||
logger.debug(`FetchHttpApi: --> ${method} ${urlForLogs}`);
|
||||
this.opts.logger?.debug(`FetchHttpApi: --> ${method} ${urlForLogs}`);
|
||||
|
||||
const headers = Object.assign({}, opts.headers || {});
|
||||
const json = opts.json ?? true;
|
||||
@@ -279,9 +278,11 @@ export class FetchHttpApi<O extends IHttpOpts> {
|
||||
priority: opts.priority,
|
||||
});
|
||||
|
||||
logger.debug(`FetchHttpApi: <-- ${method} ${urlForLogs} [${Date.now() - start}ms ${res.status}]`);
|
||||
this.opts.logger?.debug(
|
||||
`FetchHttpApi: <-- ${method} ${urlForLogs} [${Date.now() - start}ms ${res.status}]`,
|
||||
);
|
||||
} catch (e) {
|
||||
logger.debug(`FetchHttpApi: <-- ${method} ${urlForLogs} [${Date.now() - start}ms ${e}]`);
|
||||
this.opts.logger?.debug(`FetchHttpApi: <-- ${method} ${urlForLogs} [${Date.now() - start}ms ${e}]`);
|
||||
if ((<Error>e).name === "AbortError") {
|
||||
throw e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user