From d565372adbcf6a2bcc7d4795d3e0ea84a038a60c Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 13 Apr 2023 19:38:48 +0300 Subject: [PATCH] More typings --- src/LoggerClient.ts | 25 ++++++++++++++++++++++++- src/LoggerInterface.ts | 7 +++++++ src/MasterLogger.ts | 25 ++++++++++++++++++++++++- test/test.cjs | 2 +- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/LoggerInterface.ts diff --git a/src/LoggerClient.ts b/src/LoggerClient.ts index f3c00f5..d84e85e 100644 --- a/src/LoggerClient.ts +++ b/src/LoggerClient.ts @@ -3,6 +3,7 @@ import Defaults from "./Defaults.js"; import { inspect } from "node:util"; import { WriteOptions } from "./Types.js"; +import { Logger } from "./LoggerInterface.js"; type ClientOptions = { name?: string, @@ -18,7 +19,7 @@ type TransportOptions = { type: string } -class LoggerClient { +class LoggerClient implements Logger { static MaxChars = 0; @@ -88,6 +89,28 @@ class LoggerClient { } + // These methods are dynamically implemented by the constructor + // eslint-disable-next-line @typescript-eslint/no-unused-vars + error (_str: string): void { + throw new Error('Method not implemented.'); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + warn (_str: string): void { + throw new Error('Method not implemented.'); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + status (_str: string): void { + throw new Error('Method not implemented.'); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + info (_str: string): void { + throw new Error('Method not implemented.'); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + debug (_str: string): void { + throw new Error('Method not implemented.'); + } + } export default LoggerClient; \ No newline at end of file diff --git a/src/LoggerInterface.ts b/src/LoggerInterface.ts new file mode 100644 index 0000000..fb6146f --- /dev/null +++ b/src/LoggerInterface.ts @@ -0,0 +1,7 @@ +export interface Logger { + error(str: string): void + warn(str: string): void + status(str: string): void + info(str: string): void + debug(str: string): void +} \ No newline at end of file diff --git a/src/MasterLogger.ts b/src/MasterLogger.ts index 6a19835..71578e3 100644 --- a/src/MasterLogger.ts +++ b/src/MasterLogger.ts @@ -12,6 +12,7 @@ import DiscordWebhook from '@navy.gif/discord-webhook'; import Defaults, { LogLevel } from './Defaults.js'; import { Shard, WriteOptions } from './Types.js'; import { addLogLevel } from '../index.js'; +import { Logger } from './LoggerInterface.js'; const DAY = 1000 * 60 * 60 * 24; @@ -32,7 +33,7 @@ type WriteStreams = { [key:string]: fs.WriteStream } -class MasterLogger { +class MasterLogger implements Logger { #_guard: string; #_logLevel: LogLevel; @@ -225,6 +226,28 @@ class MasterLogger { return moment().format('YYYY-MM-DD HH:mm:ss'); } + // These methods are dynamically implemented by the constructor + // eslint-disable-next-line @typescript-eslint/no-unused-vars + error (_str: string): void { + throw new Error('Method not implemented.'); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + warn (_str: string): void { + throw new Error('Method not implemented.'); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + status (_str: string): void { + throw new Error('Method not implemented.'); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + info (_str: string): void { + throw new Error('Method not implemented.'); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + debug (_str: string): void { + throw new Error('Method not implemented.'); + } + } export default MasterLogger; \ No newline at end of file diff --git a/test/test.cjs b/test/test.cjs index ac54851..1e2915b 100644 --- a/test/test.cjs +++ b/test/test.cjs @@ -25,7 +25,7 @@ const logger = new MasterLogger({ console.log(logger); logger.setLogLevel(LogLevel.access); console.log(logger.logLevel); -process.exit(); +// process.exit(); logger.info('Test'); const spawn = (child) => {