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

logs2

v1.0.1

Published

一个功能强大的Node.js日志工具,支持多级别日志、自动文件轮转、日志压缩和过期清理

Readme

Logs2

一个功能强大的 Node.js 日志工具,支持多级别日志记录、自动文件轮转、日志压缩和过期清理。

功能特性

  • 多级别日志记录 (trace, debug, info, warn, error, fatal)
  • 自动按日期和级别分类存储日志文件
  • 支持通过环境变量配置日志级别和保留时间
  • 自动压缩历史日志文件以节省空间
  • 自动清理过期日志文件
  • 支持两个独立的日志实例

安装

npm install logs2

使用方法

基本使用

const { log } = require('logs2');

log.info('这是一条信息日志');
log.error('这是一条错误日志');
log.debug('这是一条调试日志');

使用自定义日志实例

const { Logger } = require('logs2');

const logger = new Logger({ logDir: './my-logs' });
logger.info('这是一条自定义日志');

使用第二个日志实例

const { log2 } = require('logs2');

log2.warn('这是第二个日志实例的消息');

发布脚本

项目包含以下npm脚本用于版本发布:

  • npm run release:patch - 发布补丁版本 (1.0.0 -> 1.0.1)
  • npm run release:minor - 发布次版本 (1.0.0 -> 1.1.0)
  • npm run release:major - 发布主版本 (1.0.0 -> 2.0.0)

这些脚本会自动更新版本号、创建git标签、推送代码到仓库并发布到npm。

环境变量配置

| 变量名 | 描述 | 默认值 | |--------|------|--------| | LOG_LEVEL | 设置日志级别 (trace, debug, info, warn, error, fatal) | info | | NODE_ENV | 设置运行环境 (development, production) | production | | LOG_RETENTION | 设置日志保留时间,支持格式如 30d, 6m, 1y | 1y | | COMPRESS_HOUR | 日志压缩任务执行小时 | 2 | | COMPRESS_MINUTE | 日志压缩任务执行分钟 | 0 | | CLEAN_HOUR | 日志清理任务执行小时 | 3 | | CLEAN_MINUTE | 日志清理任务执行分钟 | 0 |

日志文件结构

日志文件会按以下结构自动组织:

logs/
  ├── 2025/
  │   ├── 01/
  │   │   ├── 01/
  │   │   │   └── 2025-01-01_info.log
  │   │   └── 02/
  │   │       └── 2025-01-02_info.log
  └── ...

logs2/
  ├── info/
  │   ├── 2025/
  │   │   ├── 01/
  │   │   │   └── 2025-01-01_info.log
  └── ...

API

Logger 类

new Logger(options)

创建一个新的日志记录器实例。

Options
  • logDir (String) - 日志文件存储目录

logger.trace(...messages)

记录 trace 级别日志。

logger.debug(...messages)

记录 debug 级别日志。

logger.info(...messages)

记录 info 级别日志。

logger.warn(...messages)

记录 warn 级别日志。

logger.error(...messages)

记录 error 级别日志。

logger.fatal(...messages)

记录 fatal 级别日志。

预定义实例

  • log - 默认日志实例,日志存储在项目根目录的 logs 文件夹中
  • log2 - 第二个日志实例,日志存储在项目根目录的 logs2 文件夹中

许可证

MIT