包详细信息

standard-log-color

unional4.5kMIT12.1.2

Color console reporter for standard-log

自述文件

standard-log-color

NPM version NPM downloads

Github NodeJS Codecov

Visual Studio Code

[standard-log-color] provides a log reporter that will color the logger id for standard-log.

This makes the log pops and is easier to spot where the log is coming from.

Install

npm install standard-log-color
yarn add standard-log-color

Usage

import { createStandardLog } from 'standard-log'
import { createColorLogReporter } from 'standard-log-color'

const standardLog = createStandardLog({
   reporters: [createColorLogReporter({ ... })]
})

const log = standardLog.getLogger(...)
log.info('with color!')

Rendering example

By default, it will use ansi formatter in NodeJS and css formatter in browser.

If you want to change that, or use your own formatter:

import { createColorLogReporter } from 'standard-log-color'

createColorLogReporter({
  formatter: yourFormatter
})

For createCssLogFormatter(), you can specify how many colors to use:

import { createCssLogFormatter } from 'standard-log-color'

createCssLogFormatter({ maxColor: 30 })

You can also add timestamp:

import { createAnsiLogFormatter, createCssLogFormatter } from 'standard-log-color'

createAnsiLogFormatter({ timestamp: 'none' })
createAnsiLogFormatter({ timestamp: 'iso' })
createAnsiLogFormatter({ timestamp: 'elapsed' })

createCssLogFormatter({ timestamp: 'none' })
createCssLogFormatter({ timestamp: 'iso' })
createCssLogFormatter({ timestamp: 'elapsed' })