1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Remove deprecated PrefixedLogger interface (#4705)

* Add some tests for `logger`

* Remove deprecated `PrefixedLogger` interface

`PrefixedLogger` has been deprecated for some time, so let's remove it now,
while we have a major version bump.

We can tidy up some of the other logic while we're here.

Unfortunately lots of the code still uses `logger.log` which isn't exposed by
the `Logger` interface, so we need to keep exposing that where it was before.
This commit is contained in:
Richard van der Hoff
2025-02-11 13:19:46 +01:00
committed by GitHub
parent c537a361fb
commit 33648a711c
2 changed files with 80 additions and 24 deletions

51
spec/unit/logger.spec.ts Normal file
View File

@@ -0,0 +1,51 @@
/*
Copyright 2025 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* eslint-disable no-console */
import loglevel from "loglevel";
import { logger } from "../../src/logger.ts";
afterEach(() => {
jest.restoreAllMocks();
});
describe("logger", () => {
it("should log to console by default", () => {
jest.spyOn(console, "debug").mockReturnValue(undefined);
logger.debug("test1");
logger.log("test2");
expect(console.debug).toHaveBeenCalledWith("test1");
expect(console.debug).toHaveBeenCalledWith("test2");
});
it("should allow creation of child loggers which add a prefix", () => {
jest.spyOn(loglevel, "getLogger");
jest.spyOn(console, "debug").mockReturnValue(undefined);
const childLogger = logger.getChild("[prefix1]");
expect(loglevel.getLogger).toHaveBeenCalledWith("matrix-[prefix1]");
childLogger.debug("test1");
expect(console.debug).toHaveBeenCalledWith("[prefix1]", "test1");
const grandchildLogger = childLogger.getChild("[prefix2]");
expect(loglevel.getLogger).toHaveBeenCalledWith("matrix-[prefix1][prefix2]");
grandchildLogger.debug("test2");
expect(console.debug).toHaveBeenCalledWith("[prefix1][prefix2]", "test2");
});
});