Description
The matrixSDKLogLevel option passed to createMatrixAdapter does not suppress verbose logs from the matrix-js-sdk internals such as:
sync Got reply from saved sync, exists? false
sync Got saved sync token
sync Sending initial sync request...
[MatrixRTCSession !abc:example.com m.call#ROOM] No membership changes detected for room ...
This happens even when matrixSDKLogLevel: "warn" is explicitly set.
Root cause
The adapter correctly calls setLevel on the root "matrix" loglevel logger:
// node_modules/@beeper/chat-adapter-matrix/dist/index.js
const setLevel = Reflect.get(matrixSDKLogger, "setLevel");
if (typeof setLevel === "function") {
setLevel.call(matrixSDKLogger, numericLevel, false);
}
However, matrix-js-sdk does not use the root logger for most of its output. It creates independent named child loggers via loglevel.getLogger("matrix-sync"), loglevel.getLogger("matrix-MatrixRTCSession"), etc., and explicitly resets each one to DEBUG on first creation:
// matrix-js-sdk/lib/logger.js — getPrefixedLogger()
var prefixLogger = loglevel.getLogger(loggerName);
if (prefixLogger.getChild === undefined) {
prefixLogger.setLevel(loglevel.levels.DEBUG, false); // ← overrides any parent/default level
...
}
In loglevel, named loggers are fully independent instances. Setting the level on "matrix" has no effect on "matrix-sync" or "matrix-MatrixRTCSession".
Workaround
Patch loglevel.getLogger after creating the adapter so all current and future matrix-* loggers are capped at the requested level:
import loglevel from "loglevel";
// after createMatrixAdapter(...)
const _orig = loglevel.getLogger.bind(loglevel);
loglevel.getLogger = function (name: string | symbol) {
const lgr = _orig(name as string);
if (typeof name === "string" && name.startsWith("matrix")) {
lgr.setLevel("warn", false);
}
return lgr;
};
for (const [name, lgr] of Object.entries(loglevel.getLoggers())) {
if (name.startsWith("matrix")) lgr.setLevel("warn", false);
}
Expected behaviour
Setting matrixSDKLogLevel: "warn" (or "error", "silent") should suppress all matrix-js-sdk output, including logs from sync, MatrixRTC, and other internal sub-loggers.
Fix suggestion
In the adapter's initialization code, after calling setLevel on the root logger, also iterate loglevel.getLoggers() and apply the same level to all "matrix-*" entries, and optionally patch loglevel.getLogger to intercept future logger creation.
Description
The
matrixSDKLogLeveloption passed tocreateMatrixAdapterdoes not suppress verbose logs from the matrix-js-sdk internals such as:This happens even when
matrixSDKLogLevel: "warn"is explicitly set.Root cause
The adapter correctly calls
setLevelon the root"matrix"loglevel logger:However, matrix-js-sdk does not use the root logger for most of its output. It creates independent named child loggers via
loglevel.getLogger("matrix-sync"),loglevel.getLogger("matrix-MatrixRTCSession"), etc., and explicitly resets each one toDEBUGon first creation:In loglevel, named loggers are fully independent instances. Setting the level on
"matrix"has no effect on"matrix-sync"or"matrix-MatrixRTCSession".Workaround
Patch
loglevel.getLoggerafter creating the adapter so all current and futurematrix-*loggers are capped at the requested level:Expected behaviour
Setting
matrixSDKLogLevel: "warn"(or"error","silent") should suppress all matrix-js-sdk output, including logs from sync, MatrixRTC, and other internal sub-loggers.Fix suggestion
In the adapter's initialization code, after calling
setLevelon the root logger, also iterateloglevel.getLoggers()and apply the same level to all"matrix-*"entries, and optionally patchloglevel.getLoggerto intercept future logger creation.