From 32c8eb3d1cca4f30ebefb756d0c0e5c28b536abb Mon Sep 17 00:00:00 2001 From: JT2M0L3Y Date: Sat, 22 Feb 2025 16:50:54 -0600 Subject: [PATCH] Added: defined objects directory --- src/components/binder.ts | 46 +++++++++++++++++++++++++++++ src/components/index.ts | 2 ++ src/{queues => components}/queue.ts | 0 3 files changed, 48 insertions(+) create mode 100644 src/components/binder.ts create mode 100644 src/components/index.ts rename src/{queues => components}/queue.ts (100%) diff --git a/src/components/binder.ts b/src/components/binder.ts new file mode 100644 index 0000000..75e1bfe --- /dev/null +++ b/src/components/binder.ts @@ -0,0 +1,46 @@ + +/** + * @class Logger + * @description A class to handle logging messages + * @method log + */ +export class Logger { + private logPrefix: string = '' + private type: string = 'log' + + private constructPrefix(component?: string, method?: string): string { + let prefix = this.type.toUpperCase() + + if (component) { + prefix += ` [${component}` + if (method) prefix += `: ${method}` + prefix += ']' + } + + return prefix + } + + public bind(component?: string, method?: string): CallableFunction { + let tempPrefix = this.constructPrefix(component, method) + + if (tempPrefix !== this.logPrefix) this.logPrefix = tempPrefix + + switch (this.type) { + case 'warn': + return console.warn.bind(console, this.logPrefix) + case 'error': + return console.error.bind(console, this.logPrefix) + case 'log': + default: + return console.log.bind(console, this.logPrefix) + } + } + + public log(type: string, message: unknown, component?: string, method?: string): void { + if (type && type !== this.type) this.type = type + + let log = this.bind(component, method) + + log(message) + } +} diff --git a/src/components/index.ts b/src/components/index.ts new file mode 100644 index 0000000..43629b8 --- /dev/null +++ b/src/components/index.ts @@ -0,0 +1,2 @@ +export * from './queue.js' +export * from './binder.js' \ No newline at end of file diff --git a/src/queues/queue.ts b/src/components/queue.ts similarity index 100% rename from src/queues/queue.ts rename to src/components/queue.ts