More explicit type definitions

This commit is contained in:
Erik 2023-04-13 19:15:36 +03:00
parent 0d369c1995
commit d25e5f5bd7
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
2 changed files with 37 additions and 3 deletions

View File

@ -12,4 +12,9 @@ const addLogLevel = (name: string, level: number) => {
LogLevel[LogLevel[name] = level] = name;
};
export { MasterLogger, LoggerClient, Defaults, LogLevel, addLogLevel };
export {
MasterLogger,
LoggerClient, Defaults, LogLevel, addLogLevel,
};
export { LoggerClientOptions, LoggerMasterOptions } from './src/Defaults.js';

View File

@ -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
};