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

node-logger-plus

v0.2.7

Published

node console 有趣的打印 log print 打印颜色 style log 美化 带风格的日志

Downloads

45

Readme

打印日志

  • 支持来 Commonjs 和 Esmodule

  • 每次打印会返回一个Promise then 会把组装的结构已数组的结构返回

  • 可以自行处理,或者写入日志文件

  • 通过拓展运算符可以再次打印出带样式的log

  • logger

  • promise-log

暴露的函数

import { logger, Color, Logger } from 'node-logger-plus';

使用

import { logger } from 'node-logger-plus';
// const logger = require('node-logger-plus').logger;
logger.log('log', 'logger1')
logger.error('log', 'logger1')
logger.warn('log', 'logger1')
logger.info('log', 'logger1')
logger.debug('debug', 'logger1')
logger.success('log', 'logger1')
logger.table([{
    id: 1,
    name: 'logger1',
    age: 30
}]);

控制打印时机

/**
 * @desc 默认为true
 *  log: true,
    debug: true,
    info: true,
    warn: true,
    error: true,
    table: true,
 */
// 设置对于字段false 或者true 控制是否打印日志
logger.setConfig({
    debug: false, //  比如debug默认设置这个false 减少不必然的打印,在特定阶段再开启打印
});

Data

  • 如果你需要统一捕获打印的数据,你可以通过 on 来实现 内部通过Bus class 实现
logger.on('data', function (data) {
    console.log(...data.result, 'bus on data')
});

Color

  • 比如希望打印一个有颜色的字体你可以这样:
import { logger, Color } from 'node-logger-plus';
/**
 * @desc 默认内置以下颜色
    red
    green
    yellow
    blue
    magenta
    cyan
    white
 */
console.log(Color.green(msg));
// 或者
logger.log(Color.green(msg));
  • 如果你希望预设一些颜色,你可以这样
import { colors } from 'node-logger-plus';
// 例子
colors['red'] = "\x1b[31m";
colors['green'] = "\x1b[32m";

BusPlus

  • 用法和mitter方向保持一致
  • logger 内部通过继承 BusPlus 拥有 bus能力
  • https://www.npmjs.com/package/bus-plus
import { BusPlus } from 'bus-plus';
const mitter = new BusPlus();

mitter.on('message', function(data) {
    console.log(data); // test data
});
mitter.once('test', function(data) {

});
// 支持链式调用
mitter.emit('message', 'test data')
      .off('message');