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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kai-peng/log

v1.0.1

Published

在您的终端上以样式显示日志消息:-)。使用调试级别启用或禁用日志消息。

Downloads

10

Readme

log-beautify

在您的终端上以样式显示日志消息:-)。使用调试级别启用或禁用日志消息。

来源于 log-beautify,优点:

  1. TypeScript 支持
  2. 无用的文件不会被打进 npm 包

Installation

npm install @kai-peng/log-beautify

Usage

const log = require('log-beautify')

log.trace('Trace') //将级别更改为使用 trace。
log.success('Success')
log.ok('Ok') // success 别称
log.debug('Debug')
log.info('Info')
log.warning('Warning')
log.warn('Warn') //warning 别称
log.error('Error')

Use case :-)

API

Log methods

  • log.success() (文本颜色)
  • log.success_() (背景颜色)
  • log.ok() (log.success() 别称)
  • log.ok_() (log.success_() 别称)
  • log.debug()
  • log.debug_()
  • log.info()
  • log.info_()
  • log.warning()
  • log.warning_()
  • log.warn() (log.warning() 别称)
  • log.warn_() (log.warning_() 别称)
  • log.error()
  • log.error_()
  • log.show()(默认 console.log())

您可以创建自己的日志方法,例如:

log.setColors({
  custom_: 'green',
})
log.setSymbols({
  custom_: '✅ ',
})

//Now you can use it
log.custom_('Server listening on port 3000 ')

Log levels

全局级别为: 1 新日志方法的默认级别为: 1 默认级别

{
    silent: -1,//隐藏所有 log
    trace: 0,
    success: 1,
    debug: 2,
    info: 3,
    warning: 4,
    error: 5,
}

Config

  • log.useSymbols = true (启用或禁用图标)
  • log.useLabels = true (启用或禁用标签)
  • log.setColors({}) (添加或更改颜色)
  • log.setSymbols({}) (添加或更改符号)
  • log.setLabels({}) (添加或更改标签)
  • log.setTextColors({}) (更改背景日志的文本颜色)
  • log.setLevel(1) (更改全局级别,默认为 1)
  • log.setLevel(1, 'namespace') (log.setNamespaceLevel() 别名)
  • log.setNamespaceLevel(1, 'namespace') (创建带有命名空间的级别,并在当前文件中使用它,全局级别将被忽略)
  • log.namespace('namespace') (log.useNamespace() 别名)
  • log.useNamespace('namespace') (在当前文件中使用命名空间的级别,全局级别将被忽略。您可以使用在其他文件中创建的命名空间)
  • log.setLocalLevel(1) (创建仅在当前文件中使用的级别,全局级别将被忽略)
  • log.setLevels({}) (添加或更改级别)

Colors

您可以使用以下颜色格式(使用字符串):

  • keyword 例如: "red" (black,white,red,green,yellow,magenta,cyan,gray)
  • hex 例如: "#FFF000"
  • rgb 例如: "rgb(255, 255, 255)"
  • hsl 例如: "hsl(0, 100%, 50%)"
  • hsv 例如: "hsv(330, 93%, 98%)"
  • hwb 例如: "hwb(0, 100%, 0%)"

例子

/**
|--------------------------------------------------
| 禁用图标
|--------------------------------------------------
*/
log.useSymbols = false

/**
|--------------------------------------------------
| 禁用标签
|--------------------------------------------------
*/
log.useLabels = false

/**
|--------------------------------------------------
| 改变颜色
|--------------------------------------------------
*/
log.setColors({
  success: '#00FF00',
  error_: 'rgb(191,0,96)',
  info_: 'cyan',
})

/**
|--------------------------------------------------
| 添加或更改新的日志方法
|--------------------------------------------------
*/
//When you add a color, the method will automatically be created.
log.setColors({
  danger: '#FF8000',
  danger_: 'hsl(310, 99%, 57%)',
  saved: 'green',
})
//Now you can use log.danger() and log.danger_() and log.saved()

/**
|--------------------------------------------------
| 添加或者更改图标
|--------------------------------------------------
*/
log.setSymbols({
  danger: '⛔ ',
  ok: '👍 ',
  saved: '✅ ',
})

/**
|--------------------------------------------------
| 添加或者改变标签
|--------------------------------------------------
*/
log.setLabels({
  warning: 'WARNING!!!',
})

/**
|--------------------------------------------------
| 添加或更改背景日志的文本颜色
|--------------------------------------------------
*/
log.setTextColors({
  error_: 'black',
  info_: 'black',
})

/**
|--------------------------------------------------
| 添加或者更改日志级别
|--------------------------------------------------
*/
log.setLevels({
  fatal: 6,
  custom: 'info', //use info level
})

/**
|--------------------------------------------------
| 改变全局级别. 2 = "debug"
|--------------------------------------------------
*/
log.setLevel(2)
//log.setLevel('debug');

/**
|--------------------------------------------------
| 添加级别 "info = 3" 以仅在当前文件中使用,全局级别将被忽略
|--------------------------------------------------
*/
log.setLocalLevel('info')

/**
|--------------------------------------------------
| 创建带有命名空间的级别,并在当前文件中使用它,全局级别将被忽略
|--------------------------------------------------
*/
log.setNamespaceLevel('error', 'show-only-errors')

/**
|--------------------------------------------------
| 使用先前创建的命名空间。您可以使用在其他文件中创建的命名空间。
|--------------------------------------------------
*/
log.useNamespace('show-only-errors')
//log.namespace('show-only-errors');

来源

感谢

License

MIT