npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

emm-logger

v0.1.5

Published

colorful log [debug, info, warn, error, fatal]

Readme

emm-logger

带颜色的打印工具,支持命令选项来改变打印的级别,默认有五个级别:

  • debug
  • info
  • warn
  • error
  • fatal

从上往下,指定某个级别,其以及其下面的级别都会被打印。

使用 (typescript | javascript)

import { ERROR, EmmLogger } from '../index'
// const { ERROR, EmmLogger } = require('emm-logger')


let logger = new EmmLogger('demo', {
  'level': ERROR,
  'show_date': true,
})


logger.debug('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')

out out

详细

Level

通常你并不需要知道 Level 的细节,在 EmmLogger 中预定义了五个 Level

  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL

在创建 EmmLogger 实例的时候指定 option 的 level 参数,即可指定默认的日志级别,但是如果创建的 logger 是输出到文件中的,则不受此命令行参数的影响

import { ERROR, EmmLogger } from '../index'


let logger = new EmmLogger('demo', {
  'level': ERROR,
  'show_date': true,
})


logger.debug('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')

out

创建 EmmLogger

let logger = new EmmLogger(<logger name>, <options>)
  • name: name 是一个标志性的东西,它会作为输出的一部分(如上图所示)
  • options
    • level: Level 的实例,指定默认的打印级别,默认值为 WARN
    • log_path: 这是一个文件路径,默认情况下,日志是输出在终端的,log_path 允许你将日志重定向到文件中。

      如果它不存在或者并非文件,你将得到一个错误消息,注意,它并不会抛出一个错误,日志内容将会继续输出到终端; 否则日志将重定向到该文件中

    • colorful: 布尔值,是否带颜色输出;如果指定了一个正确的 log_path,则此值默认为 false,你仍可以通过命令行参数 --log-option=colorful 来打开它;否则,默认值为 true
    • show_date: 布尔值,是否输出时间,默认值为 true,你也可以通过命令行参数 --log-option=no-date 来关闭它
    • show_pretty: 布尔值,若为 false,每条日志都会被输出在一行,若为 true,则会展开输出,例如 JSON 会被层次化输出,默认值为 false,你仍可以通过命令参数 --log-option=pretty 来打开它
    • name_dyeing: { (text: string)=> string },原则上是用来装饰 name 的颜色的函数,默认值为 colors.gray
    • date_dyeing: { (text: string)=> string },原则上是用来装饰 date 的颜色的函数,默认值为 colors.gray

命令行参数

  • --log-level=<debug|info|warn|error|fatal>,强行指定所有的 EmmLogger 实例的打印级别
  • --log-option=<[no-](date|pretty|colorful)>,其中 no- 前缀表示否定

推荐写法

可以在一个诸如 utils.ts 中定义全局唯一的 logger:

import { EmmLogger } from 'emm-logger'


export const logger = new EmmLogger('emm.', { log_path: 'log.txt' })

然后在别的地方直接引用这个 logger。