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

@huan_kong/logger

v1.0.6

Published

A TypeScript logger package with multiple log levels and formatters

Readme

@huan_kong/logger

一个轻量级的 TypeScript 日志库,支持多级别日志、自定义格式化器和彩色输出。

特性

  • 🎨 彩色输出 - 基于 picocolors,支持不同日志级别的颜色区分
  • 📊 多级别日志 - 支持 DEBUG、INFO、WARN、ERROR 四个级别
  • 🔧 自定义格式化器 - 可扩展的消息格式化系统
  • TypeScript 支持 - 完整的类型定义
  • 🎯 轻量级 - 几乎零依赖(只有picocolors)

安装

npm install @huan_kong/logger
# 或
pnpm add @huan_kong/logger
# 或
yarn add @huan_kong/logger

快速开始

import { Logger, LogLevel } from '@huan_kong/logger'

// 创建 logger 实例
const logger = new Logger()

// 基本使用
logger.INFO('这是一条信息日志')
logger.WARN('这是一条警告日志')
logger.ERROR('这是一条错误日志')
logger.DEBUG('这是一条调试日志') // 默认级别下不会显示

// 设置日志级别
logger.setLevel(LogLevel.DEBUG)
logger.DEBUG('现在可以看到调试日志了')

// 支持多个参数
logger.INFO('用户登录', { userId: 123, ip: '192.168.1.1' })

配置选项

import { Logger, LogLevel, defaultFormatter } from '@huan_kong/logger'

const logger = new Logger({
  level: LogLevel.DEBUG, // 设置日志级别
  formatters: [defaultFormatter], // 自定义格式化器
})

自定义格式化器

import type { Formatter } from '@huan_kong/logger'

// 创建自定义格式化器
const customFormatter: Formatter = (...args) => {
  return args.map((arg) => {
    if (typeof arg === 'string') {
      return arg.toUpperCase()
    }
    return arg
  })
}

// 添加格式化器
logger.pushFormatter(customFormatter)

API 文档

Logger 类

构造函数

  • new Logger(options?: LoggerOptions)

日志方法

  • DEBUG(...messages: unknown[]) - 输出调试日志
  • INFO(...messages: unknown[]) - 输出信息日志
  • WARN(...messages: unknown[]) - 输出警告日志
  • ERROR(...messages: unknown[]) - 输出错误日志

配置方法

  • setLevel(level: LogLevel) - 设置日志级别
  • getLevel() - 获取当前日志级别
  • pushFormatter(formatter: Formatter) - 添加格式化器到末尾
  • unshiftFormatter(formatter: Formatter) - 添加格式化器到开头
  • removeFormatter(formatter: Formatter) - 移除指定格式化器
  • getFormatters() - 获取所有格式化器
  • setColors(colors: LogColors) - 设置颜色主题
  • getColors() - 获取当前颜色配置

日志级别

enum LogLevel {
  DEBUG = 0,
  INFO = 1,
  WARN = 2,
  ERROR = 3,
}

开发

# 安装依赖
pnpm install

# 开发模式
pnpm dev

# 构建
pnpm build

# 代码检查
pnpm lint

# 格式化代码
pnpm format

许可证

MIT © huankong233