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

spdlog4js

v1.0.0

Published

封装 C++ 的 `spdlog` 提供给 `nodejs` 服务使用。

Readme

spdlog4js

封装 C++ 的 spdlog 提供给 nodejs 服务使用。

环境需求

  1. node-gyp 安装
npm install -g node-gyp

# 验证环境
node-gyp --version
node --version     # 建议 >= 16.x
  1. 安装依赖 —— node-addon-api 是 N-API 的 C++ 封装层。

为什么不使用 N-API

N-APIC 风格接口。 而 node-addon-apiN-API 的 C++ 封装层,提供了相关的封装比如 Napi::StringNapi::Object等类

npm install node-addon-api
  1. 当前项目使用 git submodule 管理 spdlog 依赖
# 添加
git submodule add https://github.com/gabime/spdlog.git deps/spdlog

# 更新
git submodule update --init --recursive

构建流程

# 构建
node-gyp configure
# 编译
node-gyp build

# 清理 - 构建 - 编译 
# --verbose 会显示编译参数细节 方便定位问题
node-gyp clean && node-gyp configure && node-gyp build --verbose

简单的性能测试

输出 10000000 条日志

node examples/bench_example.js

[spdlog sync file]
  Total: 3566.81ms
  Ops/s: 2,803,628
  Avg:   0.36us/op

[spdlog async file]
  Total: 9099.54ms
  Ops/s: 1,098,957
  Avg:   0.91us/op

[Node.js fs.writeSync]
  Total: 9825.25ms
  Ops/s: 1,017,786
  Avg:   0.98us/op

[Node.js fs.appendFileSync]
  Total: 19588.25ms
  Ops/s: 510,510
  Avg:   1.96us/op

[pino sync file]
  Total: 15749.20ms
  Ops/s: 634,953
  Avg:   1.57us/op

[pino async file]
  Total: 20076.09ms
  Ops/s: 498,105
  Avg:   2.01us/op

[pino async (minimal)]
  Total: 25510.36ms
  Ops/s: 391,998
  Avg:   2.55us/op

Done. Check ./logs/ for output files.

使用

const assert = require("assert");
const { Logger, LogConfig, LogLevel } = require("spdlog4js");

function runExample() {
    const config = new LogConfig({
        name: "example",
        sink: "ROTATING_FILE",
        filename: "./logs/example.log",
        level: "DEBUG",
        pattern: "[%Y-%m-%d %H:%M:%S] [%^%l%$] %@ %v",
        console: true,
        setDefault: false,
        flushInterval: 3,
    });

    const logger = new Logger(config);
    assert.ok(logger, "Logger should be created");

    // 实例日志
    logger.critical("instance critical");
    logger.error("instance error");
    logger.warn("instance warn");
    logger.info("instance info");
    logger.debug("instance debug");
    logger.trace("instance trace");
    logger.flushOn(LogLevel.ERROR);
    logger.flush();
    logger.level = "warn";
    logger.critical("instance critical");
    logger.error("instance error");
    logger.warn("instance warn");
    logger.info("instance info");
    logger.debug("instance debug");
    logger.trace("instance trace");
    logger.warn();

    // 静态日志(默认 logger)
    Logger.level = "INFO";
    Logger.pattern = "[%Y-%m-%d %H:%M:%S.%f] [%^%l%$] %@ %v";
    Logger.trace("static trace");
    Logger.debug("static debug");
    Logger.info("static info");
    Logger.warn("static warn");
    Logger.error("static error");
    Logger.critical("static critical");
    Logger.flushOn(LogLevel.ERROR);
    Logger.flush();

    const level = Logger.level;
    assert.strictEqual(typeof level, "number");
    console.log(level);

    Logger.dropAll();
    console.log("example.js test passed");
}

runExample();