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/server-log

v0.1.16

Published

micl server log

Downloads

960

Readme

@micl/server-log

npm version npm downloads license

一个简单可配置的 Node.js 服务端日志工具,支持多日志级别和模块特定日志。

✨ 特性

  1. 支持多日志级别(info、warn、error)
  2. 模块特定日志管理
  3. 自动创建日志目录
  4. 日志文件按级别分类存储
  5. 控制台和文件双重输出
  6. 完整的 TypeScript 类型支持
  7. 单例模式,全局统一管理

📦 安装

npm install @micl/server-log
# or
pnpm add @micl/server-log
# or
yarn add @micl/server-log

🎯 快速使用

JavaScript

const logger = require('@micl/server-log');
const { config } = require('@micl/server-log');

// 配置日志(可选)
config({
  rootPath: './server-logs',
  modules: ['auth', 'database']
});

// 通用日志
logger.info('Server started');
logger.warn('Memory usage is high');
logger.error('Failed to connect to database');

// 模块特定日志
logger.auth.info('User login successful');
logger.database.error('Database connection lost');

TypeScript

import logger, { config } from '@micl/server-log';

// 配置日志
config({
  rootPath: './server-logs',
  modules: ['auth', 'database']
});

// 通用日志
logger.info('Server started');

// 模块特定日志
logger.auth.info('User login successful');

📚 API 参考

Logger 配置

LoggerConfig

| 配置项 | 类型 | 默认值 | 描述 | |--------|------|--------|------| | rootPath | string | './logs' | 日志文件存储根目录 | | modules | string[] | [] | 需要创建的模块日志列表 | | levels | string[] | ['info', 'warn', 'error'] | 支持的日志级别 | | files | Record<string, string> | 见下方 | 各级别对应的日志文件名 |

默认日志文件配置: | 级别 | 文件名 | |------|--------| | info | local.log | | warn | local-warn.log | | error | local-error.log |

config(options: LoggerConfig): void

更新全局配置设置。

参数:

  • options - 配置选项
config({
  rootPath: './server-logs',
  modules: ['auth', 'database'],
  levels: ['info', 'warn', 'error'],
  files: {
    info: 'app.log',
    warn: 'app-warn.log',
    error: 'app-error.log'
  }
});

日志方法

info(...args: any[]): void

输出 info 级别日志。

logger.info('Server started', { port: 3000 });

warn(...args: any[]): void

输出 warn 级别日志。

logger.warn('Memory usage is high', { usage: '85%' });

error(...args: any[]): void

输出 error 级别日志。

logger.error('Database connection failed', new Error('Connection timeout'));

模块日志

如果在配置中指定了模块,可以通过以下方式访问模块日志:

// 配置模块
config({
  modules: ['auth', 'database']
});

// 使用模块日志
logger.auth.info('User login successful');
logger.database.error('Connection lost');

📝 日志输出格式

每条日志记录包含时间戳和日志级别:

[INFO][2024-01-15 10:30:45] Server started
[WARN][2024-01-15 10:30:46] Memory usage is high
[ERROR][2024-01-15 10:30:47] Database connection failed

🤝 贡献

欢迎提交 Issue 和 Pull Request 来完善这个模块。

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。

Copyright (c) alexgogoing [email protected]

📞 支持

如有问题或建议,请提交 Issue 或联系维护者。


@micl/server-log - 简单可配置的服务端日志工具 🚀