@4lch4/logger
Advanced tools
Comparing version 0.1.0 to 0.3.0
{ | ||
"name": "@4lch4/logger", | ||
"displayName": "Logger", | ||
"version": "0.1.0", | ||
"version": "0.3.0", | ||
"description": "A small utility for logging to console within NodeJS/TypeScript applications.", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"release": "np" | ||
}, | ||
@@ -14,3 +14,3 @@ "keywords": [], | ||
"url": "https://4lch4.dev", | ||
"email": "hey@4lch4.dev" | ||
"email": "inbox@4lch4.dev" | ||
}, | ||
@@ -36,9 +36,4 @@ "bugs": { | ||
"devDependencies": { | ||
"cz-conventional-changelog": "3.3.0" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
"np": "^7.4.0" | ||
} | ||
} |
@@ -1,61 +0,46 @@ | ||
import { cyan, gray, green, red, yellow } from 'chalk' | ||
import dayjs from 'dayjs' | ||
import chalk from 'chalk' | ||
import { DefaultColors } from './defaults' | ||
import { IColorOpts, ILogger, Level, LogFormat } from './interfaces' | ||
export enum Level { | ||
info = 'info', | ||
warn = 'warn', | ||
debug = 'debug', | ||
error = 'error', | ||
success = 'success' | ||
} | ||
export class Logger implements ILogger { | ||
// private _format: LogFormat | ||
private colors: IColorOpts = DefaultColors | ||
const formatMsg = (msg: string, level: Level) => { | ||
const timestamp = dayjs().format('YYYY.MM.DD-HH.mm.ss') | ||
const prefix = [] | ||
switch (level) { | ||
case 'info': { | ||
prefix.push(gray(`[${timestamp}] - [INFO] - `)) | ||
break | ||
} | ||
constructor(_format: LogFormat, colors?: IColorOpts) { | ||
if (colors) this.colors = colors | ||
// this._format = format | ||
} | ||
case 'warn': { | ||
prefix.push(yellow(`[${timestamp}] - [WARN] - `)) | ||
break | ||
} | ||
private colorMsg(msg: string, level: Level) { | ||
return chalk.keyword(this.colors[level])(msg) | ||
} | ||
case 'debug': { | ||
prefix.push(cyan(`[${timestamp}] - [DEBUG] - `)) | ||
break | ||
} | ||
// private formatMsg(msg: string, level: Level) { | ||
// } | ||
case 'error': { | ||
prefix.push(red(`[${timestamp}] - [ERROR] - `)) | ||
break | ||
} | ||
info(msg: string) { | ||
console.log(this.colorMsg(msg, Level.info)) | ||
} | ||
case 'success': { | ||
prefix.push(green(`[${timestamp}] - [SUCCESS] - `)) | ||
break | ||
} | ||
warn(msg: string) { | ||
console.log(this.colorMsg(msg, Level.warn)) | ||
} | ||
default: { | ||
return undefined | ||
} | ||
debug(msg: string) { | ||
console.log(this.colorMsg(msg, Level.debug)) | ||
} | ||
prefix.push(msg) | ||
return prefix.join('') | ||
} | ||
error(msg: string | Error, ..._extra: any[]) { | ||
console.log(this.colorMsg(msg instanceof Error ? msg.message : msg, Level.error)) | ||
console.log(this.colorMsg(_extra.join('\n'), Level.error)) | ||
} | ||
export const logger = { | ||
info: (msg: string) => console.log(formatMsg(msg, Level.info)), | ||
warn: (msg: string) => console.log(formatMsg(msg, Level.warn)), | ||
debug: (msg: string) => console.log(formatMsg(msg, Level.debug)), | ||
error: (msg: string | Error, ..._extra: any[]) => { | ||
console.log(red(msg instanceof Error ? msg.message : msg)) | ||
console.log(red(_extra.join('\n'))) | ||
}, | ||
success: (msg: string) => console.log(formatMsg(msg, Level.success)), | ||
log: (msg: string, level: Level) => console.log(formatMsg(msg, level)) | ||
success(msg: string) { | ||
console.log(this.colorMsg(msg, Level.success)) | ||
} | ||
log(msg: string, level: any) { | ||
console.log(this.colorMsg(msg, level)) | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
11
171
1
5717
1