Updated logger
This commit is contained in:
parent
d4bd054953
commit
0ffe3d6b13
@ -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",
|
||||
|
@ -56,7 +56,7 @@ export type LoggerEvents = TypedEvents & {
|
||||
};
|
||||
|
||||
export class Logger extends TypedEmitter<LoggerEvents> {
|
||||
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<LoggerEvents> {
|
||||
}
|
||||
|
||||
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<LoggerEvents> {
|
||||
}
|
||||
|
||||
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<LoggerEvents> {
|
||||
}
|
||||
|
||||
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<LoggerEvents> {
|
||||
}
|
||||
|
||||
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<LoggerEvents> {
|
||||
}
|
||||
|
||||
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);
|
||||
|
72
src/redis.ts
72
src/redis.ts
@ -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<any>,
|
||||
// jSet: (redisKey: string, obj: any, opts?: any) => Promise<void>,
|
||||
// // hGet/hSet shimmed for objects
|
||||
// oGet: (redisKey: string) => Promise<any>;
|
||||
// oSet: (redisKey: string, obj: any) => Promise<void>,
|
||||
// // Helpers
|
||||
// findKeys: (filter: RedisKey) => Promise<string[]>,
|
||||
// forEach: (filter: RedisKey, cb: (key: string) => any) => Promise<void>,
|
||||
// };
|
||||
//
|
||||
// export async function connectRedis(retry = 3) {
|
||||
// Redis = <any>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<string[]> => {
|
||||
// const found: string[] = [];
|
||||
// await Redis.forEach(filter, (key: string) => found.push(key));
|
||||
// return found;
|
||||
// }
|
||||
// Redis.forEach = async (filter: RedisKey, cb: (key: string) => any): Promise<void> => {
|
||||
// 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);
|
||||
// };
|
||||
// }
|
Loading…
Reference in New Issue
Block a user