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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ezuikit/utils-logger

v2.1.0

Published

logger utils

Readme

Logger

日志工具类

scripts


# http://localhost:3000
pnpm run dev

pnpm run build

使用

pnpm install @ezuikit/utils-logger
export interface LoggerOptions {
  level?: 'INFO' | 'LOG' | 'WARN' | 'ERROR';
  showTime?: boolean;
  name?: string;
}
import Logger from '@ezuikit/utils-logger';

const logger = new Logger({ level: 'INFO' });

logger.info('info');
logger.log('log');
logger.warn('warn');
logger.error('error');

// 更改日志等级 WARN 只打印 warn error
logger.setOptions({ level: 'WARN' });

logger.info('setOptions info');
logger.log('setOptions log');
logger.warn('setOptions warn');
logger.error('setOptions error');

多上下文 (context)

context(key) 按 key 拿到一个互相隔离的 logger 实例,同一个 key 始终返回同一个实例,不需要自己在业务里到处传引用。

const logger = Logger({ name: 'EZUIKIT', level: 'WARN' });

const player = logger.context('player');
player.warn('ready'); // [player] [WARN] ready

// 同名复用,拿到的是同一个实例
logger.context('player') === player; // true

三条语义:

隔离 — 每个上下文有自己的配置,setOptions 只影响自己,不会影响父实例,也不会影响其他上下文。

const player = logger.context('player');
const talk = logger.context('talk');

player.setOptions({ level: 'INFO' });

player.getOptions().level; // "INFO"
logger.getOptions().level; // "WARN"  父实例不受影响
talk.getOptions().level; // "WARN"  其他上下文不受影响

继承 — 创建时继承父实例当时的配置(level、showTime 等)。之后父实例再改配置,不会追溯到已创建的上下文。

const logger = Logger({ level: 'INFO' });
const before = logger.context('before'); // 继承到 INFO

logger.setOptions({ level: 'ERROR' });
const after = logger.context('after'); // 继承到 ERROR

before.getOptions().level; // "INFO"  不被追溯修改

前缀只显示自己的 key — 不会带上父实例的 name,也不会随嵌套层级累积。

const logger = Logger({ name: 'EZUIKIT' });
logger.log('x'); // [EZUIKIT] [LOG] x
logger.context('player').log('x'); // [player] [LOG] x
logger.context('player').context('hls').log('x'); // [hls] [LOG] x

注册表管理

logger.context('player');
logger.context('talk');

logger.getContexts(); // ["player", "talk"]  已创建的 key 列表
logger.hasContext('player'); // true
logger.removeContext('talk'); // true,移除后再 context("talk") 会创建新实例

上下文实例长期持有会一直占着内存,播放器这类会反复创建销毁的场景,销毁时用 removeContext(key) 清掉即可。已经被外部持有的旧实例仍然可用,只是不再被复用。