Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@4lch4/logger

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@4lch4/logger - npm Package Compare versions

Comparing version 0.1.0 to 0.3.0

sailr.json

13

package.json
{
"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))
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc