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

@baicie/logger

v0.1.3

Published

通用日志工具模块,提供统一的日志记录功能,支持日志级别和配置

Readme

@baicie/logger

通用日志工具模块,提供统一的日志记录功能,支持日志级别和配置。

特性

  • 🎯 支持多种日志级别(debug、info、warn、error)
  • ⚙️ 灵活的配置选项
  • 🌐 兼容 SSR 环境
  • 📦 轻量级,无外部依赖
  • 🔧 TypeScript 支持

安装

pnpm add @baicie/logger

使用

基本使用

import { logger, initLogger } from '@baicie/logger'

// 初始化配置
initLogger({
  enabled: true,
  level: 'debug',
  prefix: '[MyApp]',
  showTimestamp: true,
  showLevel: true,
})

// 使用日志
logger.debug('Debug message', { key: 'value' })
logger.info('Info message')
logger.warn('Warning message')
logger.error('Error message', new Error('Something went wrong'))

// 兼容旧版代码索引日志
logger.log('LOG_CODE_001')

便捷方法

import { debug, info, warn, error, log } from '@baicie/logger'

debug('Debug message', { data: 'value' })
info('Info message')
warn('Warning message')
error('Error message')
log('LOG_CODE_001')

创建自定义 Logger 实例

import { createLoggerInstance } from '@baicie/logger'

const customLogger = createLoggerInstance({
  enabled: true,
  level: 'warn',
  prefix: '[Custom]',
})

customLogger.warn('This is a warning')

动态配置

import { logger } from '@baicie/logger'

// 获取当前配置
const config = logger.getConfig()

// 更新配置
logger.setConfig({
  enabled: true,
  level: 'error',
})

API

LoggerConfig

日志配置接口:

interface LoggerConfig {
  enabled: boolean // 是否启用日志
  force?: boolean // 是否强制输出(忽略 enabled 设置)
  level?: LogLevel // 日志级别阈值
  showTimestamp?: boolean // 是否显示时间戳
  showLevel?: boolean // 是否显示日志级别标签
  prefix?: string // 日志前缀
}

Logger

Logger 接口:

interface Logger {
  debug(codeOrMessage: LogCode | string, data?: unknown): void
  info(codeOrMessage: LogCode | string, data?: unknown): void
  warn(codeOrMessage: LogCode | string, data?: unknown): void
  error(codeOrMessage: LogCode | string, data?: unknown): void
  log(code: LogCode, force?: boolean): void
  setConfig(config: Partial<LoggerConfig>): void
  getConfig(): LoggerConfig
}

LogLevel

日志级别类型:

type LogLevel = 'debug' | 'info' | 'warn' | 'error'

日志级别

日志级别按优先级从低到高:

  1. debug - 调试信息
  2. info - 一般信息
  3. warn - 警告信息
  4. error - 错误信息

只有大于等于配置的 level 的日志才会输出。

配置说明

  • enabled: 控制是否启用日志输出,默认为 false
  • force: 强制输出日志,即使 enabledfalse,默认为 false
  • level: 日志级别阈值,只有大于等于此级别的日志才会输出,默认为 'info'
  • showTimestamp: 是否在日志消息前显示时间戳,默认为 false
  • showLevel: 是否在日志消息前显示日志级别标签,默认为 true
  • prefix: 日志消息前缀,默认为空字符串

环境支持

  • 浏览器环境
  • Node.js 环境(SSR)
  • 编译目标:ES2016

License

MIT