Implemented classic NullLogger

This commit is contained in:
Kir_Antipov 2022-12-13 14:45:07 +00:00
parent 9b882c411e
commit 65cb51a963
2 changed files with 95 additions and 0 deletions

View file

@ -0,0 +1,41 @@
import { Logger } from "./logger";
/**
* Null logger implementation, used for discarding all log messages.
*/
export class NullLogger implements Logger {
/**
* @inheritdoc
*/
fatal(_message: string | Error): void {
// NOP
}
/**
* @inheritdoc
*/
error(_message: string | Error): void {
// NOP
}
/**
* @inheritdoc
*/
warn(_message: string | Error): void {
// NOP
}
/**
* @inheritdoc
*/
info(_message: string | Error): void {
// NOP
}
/**
* @inheritdoc
*/
debug(_message: string | Error): void {
// NOP
}
}

View file

@ -0,0 +1,54 @@
import { NullLogger } from "@/utils/logging/null-logger";
describe("NullLogger", () => {
describe("constructor", () => {
test("can be created without throwing", () => {
expect(() => new NullLogger()).not.toThrow();
});
})
describe("fatal", () => {
test("can be called without throwing", () => {
const logger = new NullLogger();
expect(() => logger.fatal("message")).not.toThrow();
expect(() => logger.fatal(new Error("message"))).not.toThrow();
});
});
describe("error", () => {
test("can be called without throwing", () => {
const logger = new NullLogger();
expect(() => logger.error("message")).not.toThrow();
expect(() => logger.error(new Error("message"))).not.toThrow();
});
});
describe("warn", () => {
test("can be called without throwing", () => {
const logger = new NullLogger();
expect(() => logger.warn("message")).not.toThrow();
expect(() => logger.warn(new Error("message"))).not.toThrow();
});
});
describe("info", () => {
test("can be called without throwing", () => {
const logger = new NullLogger();
expect(() => logger.info("message")).not.toThrow();
expect(() => logger.info(new Error("message"))).not.toThrow();
});
});
describe("debug", () => {
test("can be called without throwing", () => {
const logger = new NullLogger();
expect(() => logger.debug("message")).not.toThrow();
expect(() => logger.debug(new Error("message"))).not.toThrow();
});
});
});