From 65cb51a96384e64517e0ec264fff238c1b4b681d Mon Sep 17 00:00:00 2001
From: Kir_Antipov <kp.antipov@gmail.com>
Date: Tue, 13 Dec 2022 14:45:07 +0000
Subject: [PATCH] Implemented classic `NullLogger`

---
 src/utils/logging/null-logger.ts             | 41 +++++++++++++++
 tests/unit/utils/logging/null-logger.spec.ts | 54 ++++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 src/utils/logging/null-logger.ts
 create mode 100644 tests/unit/utils/logging/null-logger.spec.ts

diff --git a/src/utils/logging/null-logger.ts b/src/utils/logging/null-logger.ts
new file mode 100644
index 0000000..5e516cd
--- /dev/null
+++ b/src/utils/logging/null-logger.ts
@@ -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
+    }
+}
diff --git a/tests/unit/utils/logging/null-logger.spec.ts b/tests/unit/utils/logging/null-logger.spec.ts
new file mode 100644
index 0000000..b38262e
--- /dev/null
+++ b/tests/unit/utils/logging/null-logger.spec.ts
@@ -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();
+        });
+    });
+});