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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ylog

v0.2.2

Published

Why another logger? That's a good question!

Readme

ylog

NPM version Build Status Dependency Status Code Climate Coverage Status

Why another logger? That's a good question!

Example:

styles

ylog 的特点:

  • 支持 npmlog 的 level 级别
  • 支持 debug 的多模块控制
  • 支持 自定义 grunt log 的丰富样式
  • 支持 指定每行的输出宽度 (wrap)
  • 支持 简单的类似于 markdown 的语法
  • 支持 显示执行时间
  • 支持 显示进程 ID
  • 支持 事件监听
  • 支持 进度条 输出 (使用了 gaugeare-we-there-yet )

Usage

使用 levels

styles

设置 level 显示级别

ylog.setLevel(levels, mode)

levels 可以是单个 level,也可以是一个 level 数组 mode 可以是 'only''weight'

  • only mode: 表示只输出 levels 中指定的级别,其它级别不输出

  • weight mode: 表示只输出权重__大于等于__所有指定 levels 中的最低权重的级别(默认是此值)

自定义新的 level,或修改现有 level

ylog.levelFlag(name, weight, tag)


// 修改
c.levelFlag('ok', 5000, 'ok');

// 添加
c.levelFlag('ok2', 5500, chalk.bold.green('✓'));

使用 namespace

很简单,像使用 debug 一样,只是环境变量名从 DEBUG 变成了 YLOG

styles

使用丰富的样式

styles

自定义你自己的样式

ylog.styleFlag(name, fn)

name: 是样式名称

fn: 的参数是你执行是填的参数,fn 需要返回一个字符串


// 定义一个简单的换行样式(默认有个 ln,它输出的换行是在左边)

ylog.styleFlag('rightLn', function(str) {
  return (str || '') + '\n';
})

// 现在你就可以这样用

ylog.rightLn('are you ok');

使用类 markdown 语法

styles

配置(或者叫 attributes)

styles

局部配置

有两种方式:

  • ylog.attr({md: true, time: false, wrap: 80}).log('...')
  • ylog.md.no.time.wrap(80).log('...');

全局配置

你可以使用 ylog.attributes 对像,直接修改属性的默认值,它会影响全局的配置

显示执行时间

只要打开全局配置 time 来即可

ylog.attributes.time = true;

显示进程 ID

配置 ylog.Tag 属性

ylog.Tag.pid.show = true;

事件监听


var logger = ylog('myNamespace');

logger.on('myNamespace.ok', function() {

});

logger.ok('ok');      // => 会触发上面的监听
logger.info('info');  // => 不会触发上面的监听

使用进度条

var ylog = require('ylog');
var fs = require('fs');

var p = ylog.progress('progress', {theme: 'ascii'});

var basicJob = p.addJob('job 1', 1000, 2);
basicJob.complete(10);

//basicJob progress
var sid = setInterval(function() {
  basicJob.complete(100);
}, 500);

// streamJob progress
fs.stat(__filename, function(err, stats) {
  if (err) { throw err; }

  var streamJob = p.addJob('job 2', stats.size, true);

  setTimeout(function() {
    fs.createReadStream(__filename).pipe(streamJob).on('data', function() {
      // do your thing
    });
  }, 200)

});


p.on('finished', function(name) {
  p.hide();
  console.log('finished ' + name);
  clearInterval(sid);
});

History

CHANGELOG

License

Copyright (c) 2015 Zhonglei Qiu. Licensed under the MIT license.