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

jdf-log

v0.0.4

Published

jdf log module

Downloads

8

Readme

jdf-log

jdf使用的日志模块,基于winston

Methods

  • level(levelName) get/set 设置日志优先级,采用npm的level方式,共5个日志级别
{ error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }

日志级别越高,显示的内容越多。如果不给参数,就返回当前的日志级别,如果给定参数就设置成需要的级别。

  • profile(name,[startFormatter], [endFormatter]) 获取某个函数的执行时间,开始调用一次,结束调用一次,startFormatterendFormatter为可选参数,如果不提供则会有一个默认的日志输出。默认的格式是:
`Starting '${name}'...`
`Finished '${name}' after ${timeSpan} ms`

你可以提供自定义的输出,注意他们的参数,startFormatter给定的是name,而endFormatter给定的是name和timeSpan,timeSpan单位是ms,你可以仅在开始的时候提供startFormatter和endFormatter:

const startFn = (name) => {
    logger.info(`Run ${name}`);
}

const endFn = (name, timeSpan) => {
    logger.info(`Finish ${name}, uesd about ${timeSpan} ms`)
}

logger.profile('test command', startFn, endFn);
setTimeout(function() {
    logger.profile('test command');
},1234);

// output
Run test command
Finish test command, used about 1234 ms
  • error(), warn(), info(), verbose(), debug(), silly() 参考winston的对应函数

Work in jdf

jdf的入口处获取参数,看是否需要verbose方式,内部的日志,常规显示的可以用logger.info(),需要啰嗦模式的就用logger.verbose(),当然如果需要更啰嗦的方式,可以用logger.debug(),根据入口的配置设置显示的level级别即可,现在 verbose 级别的日志级别名称,会在最后展示的时候设置成info,主要是为了统一,其他的都还是原来的日志级别的名字

一个简单的demo

const logger = require('jdf-log');

logger.level('verbose');

logger.profile('output');
logger.warn('Hello distributed log files! %d aaa %d', 123, 456);
logger.info('this is step one');
logger.info('this is step two');
logger.silly('ni da yeeeee de'); // 当前日志级别是verbose,所有silly级别的日志不会显示
logger.error(new Error('this is an error').message);
logger.verbose('Verboseeeeeeeeeeeeeeeeeee!');
setTimeout(() => {
  logger.profile('output');
},1000);

输出为:

[09:58:27] Starting 'output'...
[09:58:27] WARN Hello distributed log files! 123 aaa 777
[09:58:27] INFO this is step one
[09:58:27] INFO this is step two
[09:58:27] ERROR this is an error
[09:58:27] INFO Verboseeeeeeeeeeeeeeeeeee!
[09:58:28] Finished 'output' after 1012 ms