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

@jerryc/mini-logger

v0.0.4

Published

A mini logger with four level

Readme

mini-logger

CircleCI

NPM Version NPM Downloads Coverage Status npm bundle size

一个迷你小 Logger,它可以:

  1. 提供最小的 4 个 log level,你可以根据不同需要来控制日志输出 level。
  2. 提供 onLog 钩子, 方便你扩展你需要的逻辑。
  3. 以及提供 prefix, title template 来个性化输出的日志样式。

Quick Usage

  1. Install

    $ npm install @jerryc/mini-logger
  2. Import and use

    import { Logger } from '@jerryc/mini-logger';
    const logger = new Logger();
    
    logger.error('Hi');
    logger.warn('Hi');
    logger.info('Hi');
    logger.debug('Hi');
    
    // 输出:[error] Hi
    // 输出:[warn] Hi
    // 输出:[info] Hi
    // 输出:[debug] Hi

Level 控制

Level 有级别之分,new Logger({ level }) 时可以定义最低的 level,那么在比此 level 高的级别日志,就会被输出。

Level 级别:

| Level | 级别 | | ----------- | ---- | | Level.ERROR | 1 | | Level.WARN | 2 | | Level.INFO | 3 | | Level.DEBUG | 4 |

如:

import { Logger, Level } from '@jerryc/mini-logger';
const logger = new Logger({ level: Level.ERROR });

logger.info('Hi, i am info');
logger.error('Hi, i am error');

// 输出: Hi, i am error

运行时更新 level

logger.level = Level.INFO;

logger.info('Hi, i am info');
logger.error('Hi, i am error');

// 输出: Hi, i am info
// 输出: Hi, i am error

个性化格式输出

默认输出格式:[prefix:level] log content,支持输出格式的自定义。

1. 使用 prefix 来区分模块

import { Logger, Level } from '@jerryc/mini-logger';
const userLogger = new Logger({
  prefix: 'user-services',
});

const goodsLogger = new Logger({
  prefix: 'goods-services',
});

userLogger.info('hi, i am info');
// 输出:[user-services:info] hi, i am info

goodsLogger.info('hi, i am info');
// 输出:[goods-services:info] hi, i am info

2. 使用 titleTemplate 来更个性化改变格式

import { Logger, Level } from '@jerryc/mini-logger';

const logger = new Logger({
  prefix: 'my-logger',
  titleTemplate: ({ prefix, level }) => {
    return `[${prefix}-${levelMapper[level]}]`;
  },
});

logger.info('hi, i am info');
// 输出:[my-logger-info] hi, i am info

通过 onLog 钩子,进行更自定义的逻辑

const logger = new Logger({
  onLog: (level, args) => {
    console.log({ level, args });
    // 连接自建的日志上报系统...
  },
});

logger.info('hi, i am info');

// 输出:{ level: 3, args: [ 'hi, i am info' ] }

API

详见:https://jerryc8080.github.io/mini-logger/

测试覆盖率

详见:https://jerryc8080.github.io/mini-logger/coverage/index.html