From d25e5f5bd7c2a2e4d814cb1f82d6c9acaef69dc2 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 13 Apr 2023 19:15:36 +0300 Subject: [PATCH] More explicit type definitions --- index.ts | 7 ++++++- src/Defaults.ts | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 0516524..4147eda 100644 --- a/index.ts +++ b/index.ts @@ -12,4 +12,9 @@ const addLogLevel = (name: string, level: number) => { LogLevel[LogLevel[name] = level] = name; }; -export { MasterLogger, LoggerClient, Defaults, LogLevel, addLogLevel }; \ No newline at end of file +export { + MasterLogger, + LoggerClient, Defaults, LogLevel, addLogLevel, +}; + +export { LoggerClientOptions, LoggerMasterOptions } from './src/Defaults.js'; \ No newline at end of file diff --git a/src/Defaults.ts b/src/Defaults.ts index 8092180..ad697f3 100644 --- a/src/Defaults.ts +++ b/src/Defaults.ts @@ -1,3 +1,5 @@ +import { WebhookClientOptions } from "@navy.gif/discord-webhook/build/esm/src/types/Webhook"; + enum LogLevel { debug = 0, info = 1, @@ -42,6 +44,14 @@ const customTypes: string[] = []; const guard = '_logger'; const webhook: { url?: string, id?: string, token?: string } = {}; +type LogLevelType = { + debug: LogLevel, + info: LogLevel, + status: LogLevel, + warn: LogLevel, + error: LogLevel +} + const logLevelMapping = { debug: LogLevel.debug, info: LogLevel.info, @@ -50,14 +60,31 @@ const logLevelMapping = { error: LogLevel.error }; -const SharedOptions = { +type SharedOptionsType = { + guard: string, + customStreams: string[] + logLevel: LogLevel, + logLevelMapping: LogLevelType +} + +const SharedOptions: SharedOptionsType = { guard, customStreams, logLevel: LogLevel.info, logLevelMapping, }; -const MasterOptions = { +export type LoggerMasterOptions = SharedOptionsType & { + fileRotationFreq: number, + directory: string, + customTypes: string[], + customTypeMapping: { [key: string]: string }, + customColours: { [key: string]: number | string }, + broadcastLevel: number, + webhook: WebhookClientOptions, +} + +const MasterOptions: LoggerMasterOptions = { ...SharedOptions, fileRotationFreq: 1, directory: './logs', @@ -68,6 +95,8 @@ const MasterOptions = { webhook, }; +export type LoggerClientOptions = SharedOptionsType; + const ClientOptions = { ...SharedOptions };