From 0ffe3d6b13d893c8d32ee52551c9a3a870ecb971 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sun, 3 Mar 2024 19:26:20 -0500 Subject: [PATCH] Updated logger --- package.json | 2 +- src/logger.ts | 12 ++++----- src/redis.ts | 72 --------------------------------------------------- 3 files changed, 7 insertions(+), 79 deletions(-) delete mode 100644 src/redis.ts diff --git a/package.json b/package.json index b39c2ec..5067304 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/js-utilities", - "version": "0.3.4", + "version": "0.3.5", "description": "JavaScript Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/logger.ts b/src/logger.ts index 8acaff2..405949f 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -56,7 +56,7 @@ export type LoggerEvents = TypedEvents & { }; export class Logger extends TypedEmitter { - static LOG_LEVEL: LOG_LEVEL = LOG_LEVEL.INFO; + static LOG_LEVEL: LOG_LEVEL = LOG_LEVEL.VERBOSE; constructor(public readonly namespace?: string) { super(); @@ -78,7 +78,7 @@ export class Logger extends TypedEmitter { } debug(...args: string[]) { - if(LOG_LEVEL.VERBOSE >= Logger.LOG_LEVEL) { + if(Logger.LOG_LEVEL >= LOG_LEVEL.VERBOSE) { const str = this.format(...args); Logger.emit(LOG_LEVEL.VERBOSE, str); console.debug(CliForeground.LIGHT_GREY + str + CliEffects.CLEAR); @@ -86,7 +86,7 @@ export class Logger extends TypedEmitter { } error(...args: string[]) { - if(LOG_LEVEL.ERROR >= Logger.LOG_LEVEL) { + if(Logger.LOG_LEVEL >= LOG_LEVEL.ERROR) { const str = this.format(...args); Logger.emit(LOG_LEVEL.ERROR, str); console.error(CliForeground.RED + str + CliEffects.CLEAR); @@ -94,7 +94,7 @@ export class Logger extends TypedEmitter { } info(...args: string[]) { - if(LOG_LEVEL.INFO >= Logger.LOG_LEVEL) { + if(Logger.LOG_LEVEL >= LOG_LEVEL.INFO) { const str = this.format(...args); Logger.emit(LOG_LEVEL.INFO, str); console.info(CliForeground.BLUE + str + CliEffects.CLEAR); @@ -102,7 +102,7 @@ export class Logger extends TypedEmitter { } log(...args: string[]) { - if(LOG_LEVEL.INFO >= Logger.LOG_LEVEL) { + if(Logger.LOG_LEVEL >= LOG_LEVEL.INFO) { const str = this.format(...args); Logger.emit(LOG_LEVEL.INFO, str); console.log(CliEffects.CLEAR + str); @@ -110,7 +110,7 @@ export class Logger extends TypedEmitter { } warn(...args: string[]) { - if(LOG_LEVEL.WARN >= Logger.LOG_LEVEL) { + if(Logger.LOG_LEVEL >= LOG_LEVEL.WARN) { const str = this.format(...args); Logger.emit(LOG_LEVEL.WARN, str); console.warn(CliForeground.YELLOW + str + CliEffects.CLEAR); diff --git a/src/redis.ts b/src/redis.ts deleted file mode 100644 index 2d0d601..0000000 --- a/src/redis.ts +++ /dev/null @@ -1,72 +0,0 @@ -// import {createClient, RedisClientType} from 'redis'; -// import {environment} from '../environments/environment'; -// -// export type RedisKey = string | string[]; -// -// export let Redis!: RedisClientType & { -// // get/set shimmed for JSON -// jGet: (redisKey: string) => Promise, -// jSet: (redisKey: string, obj: any, opts?: any) => Promise, -// // hGet/hSet shimmed for objects -// oGet: (redisKey: string) => Promise; -// oSet: (redisKey: string, obj: any) => Promise, -// // Helpers -// findKeys: (filter: RedisKey) => Promise, -// forEach: (filter: RedisKey, cb: (key: string) => any) => Promise, -// }; -// -// export async function connectRedis(retry = 3) { -// Redis = createClient({ -// url: `redis://host:port` -// }); -// if(!Redis && retry > 0) { -// await connectRedis(retry - 1); -// } else if(!!Redis) { -// Redis.jGet = async (redisKey: string) => { -// const val = await Redis.get(redisKey); -// return val ? JSON.parse(val) || val : null; -// }; -// Redis.jSet = (redisKey: string, obj: any, opts?: any) => { -// return Redis.set(redisKey, JSON.stringify(obj), opts).then(() => {}); -// }; -// Redis.oGet = async (redisKey: string) => { -// if(!(await Redis.hLen(redisKey))) return null; -// const val = await Redis.hGetAll(redisKey); -// Object.entries(val).forEach(([key, v]) => val[key] = JSON.parse(v)); -// return val; -// }; -// Redis.oSet = (redisKey: string, obj: any) => { -// const r = Redis.multi(); -// Object.entries(obj).forEach(([key, val]) => { -// r.hSet(redisKey, key, JSON.stringify(val)); -// }); -// return r.exec().then(() => {}); -// }; -// Redis.findKeys = async (filter: RedisKey): Promise => { -// const found: string[] = []; -// await Redis.forEach(filter, (key: string) => found.push(key)); -// return found; -// } -// Redis.forEach = async (filter: RedisKey, cb: (key: string) => any): Promise => { -// for await (const k of Redis.scanIterator({MATCH: createKey(filter)})) { -// const rtn = cb(k); -// if(rtn instanceof Promise) await rtn; -// } -// } -// await Redis.connect(); -// } -// } -// -// export function createKey(...keys: (string | string[])[]) { -// return keys.flat().map(k => k == null ? '*' : k).join(':'); -// } -// -// export function namespacedKey(namespace: string, key: RedisKey): string { -// return createKey(namespace, ...(Array.isArray(key) ? key : [key])); -// } -// -// export function nameSpacer(namespace: string) { -// return (key: RedisKey) => { -// return namespacedKey(namespace, key); -// }; -// }