@crowlog/logger

中文文档
2.2.2发布于 2026/01/04MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3189

Ultra lightweight, zero-dependency, extendable logging library for any JavaScript environment. Works in Node.js, browsers, and edge runtimes.

原始使用文档
文档目录16 节
  1. Features
  2. Installation
  3. Usage
  4. Methods
  5. Child logger and factory
  6. Transports
  7. Plugins
  8. Filter Plugin
  9. Redact Plugin
  10. Global Context Plugin
  11. Async Context Plugin
  12. Pretty Logging
  13. Testing
  14. Comparison
  15. License
  16. Credits

Header banner

Crowlog - Extendable JS logging library

Crowlog is a simple, lightweight, zero-dependency, and extendable logging library for any JavaScript environment.

Docs   •   GitHub   •   NPM

Features

  • Ultra lightweight - Crowlog is very lightweight (less than 1kB minified + gzipped, see comparison).
  • Zero dependencies - No runtime dependencies, just pure JavaScript.
  • Extendable - Crowlog is designed to be extendable, so you can add your own transports and plugins to it.
  • Simple - Crowlog is designed to be simple and easy to use.
  • Fully typed - Crowlog is fully typed, so you can get autocomplete and type safety when using it.
  • Any environment - Crowlog works in any environment, including Node.js, browsers, and the edge.
  • Testing friendly - Crowlog is designed to be testing friendly, so you can easily test your logs with the in-memory transport.
  • Slightly opinionated - Crowlog is designed to be slightly opinionated, so it has a default transport and some plugins.
  • Pretty logs - Crowlog pretty log command to display logs in a more readable format for development.

Installation

# pnpm
pnpm install @crowlog/logger

# npm
npm install @crowlog/logger

# yarn
yarn add @crowlog/logger

Usage

Basic usage:

import { createLogger } from '@crowlog/logger';

const logger = createLogger({ namespace: 'my-app' });

logger.info('Hello world');
logger.error({ error: new Error('...') }, 'Something went wrong');

[!NOTE] The logging interface is either a single string message or a data object and a message string tuple.

logger.info('Hello world');
logger.info({ foo: 'bar' }, 'Hello world');

Methods

Crowlog logger provides 4 different logging methods: debug, info, warn, and error.

logger.debug(/* ... */);
logger.info(/* ... */);
logger.warn(/* ... */);
logger.error(/* ... */);

Child logger and factory

Crowlog logger provides a createChildLogger method to create a child logger that inherit the configuration of the parent logger.

import { createLogger } from '@crowlog/logger';

const logger = createLogger({ namespace: 'my-app' });
const childLogger = logger.createChildLogger({ namespace: 'child' });

Alternatively, you can use the createLoggerFactory to create a logger factory that can be used to create child loggers with the same configuration.

import { createLoggerFactory } from '@crowlog/logger';

const createLogger = createLoggerFactory({ transports: /* ... */, plugins: /* ... */ });
const logger = createLogger({ namespace: 'child' });

Transports

Transports control where logs are sent. By default, Crowlog uses the stdout transport (outputs JSON to console).

import { createLogger, createStdoutLoggerTransport } from '@crowlog/logger';

// Customize serialization
const logger = createLogger({
  namespace: 'my-app',
  transports: [
    createStdoutLoggerTransport({
      serialize: ({ level, message }) => `[${level}] ${message}`
    })
  ]
});

For testing, use the in-memory transport:

import { createInMemoryLoggerTransport } from '@crowlog/logger';

const inMemoryTransport = createInMemoryLoggerTransport();
const logger = createLogger({
  namespace: 'my-app',
  transports: [inMemoryTransport]
});

logger.info('Test log');
const logs = inMemoryTransport.getLogs({ excludeTimestampMs: true });

See the full documentation for more details on transports and how to create custom ones.

Plugins

Plugins extend logger functionality with filtering, redaction, and context management.

Filter Plugin

Control which logs reach transports:

import { createLogger, createFilterPlugin } from '@crowlog/logger';

const logger = createLogger({
  namespace: 'my-app',
  plugins: [
    createFilterPlugin({
      minLevel: 'info',  // Only info and above
      excludedNamespaces: ['debug-utils']  // Exclude specific namespaces
    })
  ]
});

Redact Plugin

Automatically hide sensitive data:

import { createRedactPlugin } from '@crowlog/logger';

const logger = createLogger({
  namespace: 'my-app',
  plugins: [
    createRedactPlugin({
      paths: ['password', 'apiKey', 'user.email']
    })
  ]
});

logger.info({ password: 'secret', username: 'alice' }, 'Login');
// Output: { password: '[redacted]', username: 'alice' }

Global Context Plugin

Add application-wide context to all logs:

import { createGlobalLogContextPlugin } from '@crowlog/logger';

const { globalContextPlugin, setGlobalLogContext } = createGlobalLogContextPlugin();

const logger = createLogger({
  namespace: 'my-app',
  plugins: [globalContextPlugin]
});

setGlobalLogContext({ environment: 'production', version: '1.0.0' });
logger.info('Started'); // Includes environment and version

Async Context Plugin

Add request-scoped context (requires async_hooks support):

import { createAsyncContextPlugin, wrapWithLoggerContext } from '@crowlog/async-context-plugin';

const logger = createLogger({
  namespace: 'my-app',
  plugins: [createAsyncContextPlugin()]
});

wrapWithLoggerContext({ requestId: '123' }, () => {
  logger.info('Processing'); // Includes requestId
});

See the full documentation for more details on plugins and how to create custom ones.

Pretty Logging

Format JSON logs for development with @crowlog/pretty:

node index.js | npx crowlog-pretty

log-screenshot

See the pretty logging guide for more details.

Testing

Use the in-memory transport to capture logs in tests, or the noop logger to disable logging entirely:

import { createNoopLogger } from '@crowlog/logger';

// No logs will be produced
const result = doSomething({ logger: createNoopLogger() });

See the testing guide for more details.

Comparison

LibraryRuntime dependenciesBundled size
@crowlog/[email protected]0 dependencies1.3kB (674B minified + gzipped) source
[email protected]11 dependencies7.5kB (2.9kb minified + gzipped) source
[email protected]11 dependencies147.9kB (37.4kB minified + gzipped) source
[email protected]19 dependencies15.7kB (5.6kB minified + gzipped) source

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Credits

This project is crafted with ❤️ by Corentin Thomasset. If you find this project helpful, please consider supporting my work.

The icon is the Raven Rounded from the Material Symbols.

版本与发布记录

@crowlog/logger 共发布 13 个版本,首次发布于 2025/02/07;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.2.2latest2026/01/0410 个月前
2.2.12026/01/0210 个月前
2.2.02025/12/2910 个月前
2.1.02025/11/1611 个月前
2.0.02025/10/011.1 年前
1.2.12025/04/211.6 年前

关于 @crowlog/logger 的常见问题

@crowlog/logger 是什么?

Ultra lightweight, zero-dependency, extendable logging library for any JavaScript environment. Works in Node.js, browsers, and edge runtimes.

如何安装 @crowlog/logger?

在项目目录运行 npm install @crowlog/logger,或使用 pnpm add / yarn add / bun add。

@crowlog/logger 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@crowlog/logger 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@crowlog/logger 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@crowlog/logger 可以商用吗?

@crowlog/logger 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@crowlog/logger 的下载量有多少?

根据 npm 官方下载统计,@crowlog/logger 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,189 次,日均约 106 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@crowlog/logger 还在维护吗?

最新版本 2.2.2 发布于 2026/01/04(10 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 4 个;首次发布于 2025/02/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。