mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 08:20:58 -05:00
Implemented classic NullLogger
This commit is contained in:
parent
9b882c411e
commit
65cb51a963
2 changed files with 95 additions and 0 deletions
41
src/utils/logging/null-logger.ts
Normal file
41
src/utils/logging/null-logger.ts
Normal 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
|
||||
}
|
||||
}
|
54
tests/unit/utils/logging/null-logger.spec.ts
Normal file
54
tests/unit/utils/logging/null-logger.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue