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

@micl/logger

v0.0.1

Published

一个轻量、可配置、支持模块化的 **Node.js 日志管理工具**,用于统一控制服务端日志的输出格式、日志等级与模块前缀。

Readme

@micl/logger

一个轻量、可配置、支持模块化的 Node.js 日志管理工具,用于统一控制服务端日志的输出格式、日志等级与模块前缀。

适合:

  • Node.js 后端服务
  • CLI / 脚本工具
  • Monorepo / 多模块项目

✨ 特性

  • ✅ 单例 Logger,全局统一日志实例
  • ✅ 支持日志等级控制(info / warn / error)
  • ✅ 支持日志前缀(服务名 / 模块名)
  • ✅ 支持按模块初始化子 Logger
  • ✅ TypeScript 类型完整
  • ✅ 低侵入、开箱即用

📦 安装

npm install @micl/logger

🚀 快速使用

import logger from '@micl/logger'

logger.info('service started')
logger.warn('cache miss')
logger.error('db error')

输出示例:

[INFO] service started
[WARN] cache miss
[ERROR] db error

🧱 日志等级(LOG_LEVEL)

export enum LOG_LEVEL {
  INFO_ONLY = 'info',
  WARN_ONLY = 'warn',
  ERROR_ONLY = 'error',
  WARN = 'info, warn',
  ERROR = 'info, warn, error'
}

| 枚举值 | 含义 | |------|------| | INFO_ONLY | 仅输出 info | | WARN_ONLY | 仅输出 warn | | ERROR_ONLY | 仅输出 error | | WARN | 输出 info + warn | | ERROR | 输出 info + warn + error |


⚙️ 全局配置(LOG_CONF)

export const LOG_CONF = {
  close: false,
  level: LOG_LEVEL.ERROR,
  head: ''
}

| 配置项 | 说明 | |------|------| | close | 是否关闭所有日志 | | level | 当前日志输出等级 | | head | 全局日志头(前缀) |


🧩 Logger 单例

获取实例

import logger from '@micl/logger'

const log = logger.getInstance()

设置日志前缀

logger.setPrefix('user-service')
logger.info('service started')

输出:

[user-service] service started

📡 Server Logger(模块化日志)

@micl/logger 支持为不同模块生成独立的日志对象,方便在大型项目中区分日志来源。

初始化模块日志

import { initServerLog, serverLogger } from '@micl/logger'

initServerLog(['user', 'order', 'auth'])

使用模块日志

serverLogger.user?.info('user created')
serverLogger.order?.warn('order timeout')
serverLogger.auth?.error('auth failed')

每个模块都拥有:

interface InnerServerLoggerInterface {
  info(): void
  warn(): void
  error(): void
}

🧪 TypeScript 接口说明

export interface ServerLoggerInterface {
  [key: string]: InnerServerLoggerInterface | (() => void) | undefined
}

支持通过 key 动态访问模块 Logger。


📐 设计说明

  • 使用 单例模式,保证全局日志一致性
  • 日志等级在运行期可控
  • 模块化日志适合服务端复杂业务拆分
  • 默认输出到 console,可扩展到文件 / 远程日志

🔌 扩展建议

  • 输出到文件(File Transport)
  • 接入 ELK / Loki
  • 注入 traceId / requestId
  • 与 OpenTelemetry 结合

📄 License

MIT