New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

colorful-chalk-logger

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colorful-chalk-logger

a colorful logger, support control output(format | level) through command-line options.

  • 0.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31
Maintainers
1
Weekly downloads
 
Created
Source

colorful-chalk-logger is a colorful logger tool based on chalk(so you can use a lot of colors) and commander(so you can use command line parameters to customized the logger's behavior).

Install

you can use colorful-chalk-logger either in typescript or javascript.

yarn add colorful-chalk-logger
// or
npm install --save colorful-chalk-logger

cli-options

  • --log-level <debug|verbose|info|warn|error|fatal>: index global logger level.
  • --log-flag <[no-](date|inline|colorful)>: the prefix no- represent negation.
    • date: whether to print date.
    • inline: each log record output in one line.
    • colorful: whether to print with colors.

Example

// demo/demo1.ts
import { ColorfulChalkLogger, ERROR } from '../index'

let logger = new ColorfulChalkLogger('demo', {
  level: ERROR,   // the default value is DEBUG
  date: false,    // the default value is false.
  colorful: true, // the default value is true.
})


logger.debug('A', 'B', 'C')
logger.verbose('A', 'B', 'C')
logger.info('a', 'b', 'c')
logger.warn('X', 'Y', 'Z', { a: 1, b: 2})
logger.error('x', 'y', 'z', { c: { a: 'hello' }, b: { d: 'world' } })
logger.fatal('1', '2', '3')

demo1.1.png

Custom output format:

// demo/demo2.ts
import { ColorfulChalkLogger, ERROR } from '../index'
import { Level } from '../src/level'
import chalk from 'chalk'


let logger = new ColorfulChalkLogger('demo', {
  level: ERROR,   // the default value is DEBUG
  date: false,    // the default value is false.
  colorful: true, // the default value is true.
})


logger.formatHeader = function (level: Level, date: Date): string {
  let { desc } = level
  let { name } = this
  if( this.flags.colorful ) {
    desc = level.headerChalk.fg(desc)
    desc = level.headerChalk.bg(desc)
    name = chalk.gray(name)
  }
  let header = `${desc} ${name}`
  if( !this.flags.date) return `[${header}]`

  let dateString = date.toLocaleTimeString()
  if( this.flags.colorful ) dateString = chalk.gray(dateString)
  return `<${dateString} ${header}>`
}


logger.debug('A', 'B', 'C')
logger.verbose('A', 'B', 'C')
logger.info('a', 'b', 'c')
logger.warn('X', 'Y', 'Z', { a: 1, b: 2})
logger.error('x', 'y', 'z', { c: { a: 'hello' }, b: { d: 'world' } })
logger.fatal('1', '2', '3')

demo2.1.png

// demo/demo3.ts
import { ColorfulChalkLogger, ERROR } from '../index'
import { Level } from '../src/level'
import chalk from 'chalk'


let logger = new ColorfulChalkLogger('demo', {
  level: ERROR,     // the default value is DEBUG
  date: false,      // the default value is false.
  colorful: true,   // the default value is true.
  dateChalk: 'green',
  nameChalk: chalk.cyan.bind(chalk),
})


logger.debug('A', 'B', 'C')
logger.verbose('A', 'B', 'C')
logger.info('a', 'b', 'c')
logger.warn('X', 'Y', 'Z', { a: 1, b: 2})
logger.error('x', 'y', 'z', { c: { a: 'hello' }, b: { d: 'world' } })
logger.fatal('1', '2', '3')

demo3.1.png

Keywords

FAQs

Package last updated on 24 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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