@faremeter/logs

中文文档
0.22.0发布于 2026/05/27LGPL-3.0-onlyTypeScriptESM + CJS零依赖近 30 天下载 3200

A configurable logging abstraction for Faremeter

原始使用文档
文档目录21 节
  1. Installation
  2. Features
  3. API Reference
  4. Functions
  5. shouldLog
  6. ConsoleBackend.debug
  7. configureApp
  8. getLogger
  9. Constants
  10. LogLevels
  11. Interfaces
  12. Logger
  13. LoggingBackend
  14. ConfigureAppArgs
  15. Types
  16. LogLevel
  17. Context
  18. LogArgs
  19. BaseConfigArgs
  20. Related Packages
  21. License

@faremeter/logs

A configurable logging abstraction with pluggable backends.

Installation

pnpm install @faremeter/logs

Features

  • Unified logging interface across all packages
  • Pluggable backends (console, logtape)
  • Hierarchical logger naming
  • Runtime backend swapping

API Reference

Functions

shouldLog

FunctionType
shouldLog(level: "trace" or "debug" or "info" or "warning" or "error" or "fatal", configuredLevel: "trace" or "debug" or "info" or "warning" or "error" or "fatal") => boolean

ConsoleBackend.debug

FunctionType
ConsoleBackend.debug(message: string, context?: Context or undefined) => void

configureApp

Initializes the global logging system.

Call this once at application startup to configure the log level and backend. If no backend is specified, logtape is used when available, otherwise falls back to console output.

FunctionType
configureApp(args?: ConfigureAppArgs) => Promise<void>

Parameters:

  • args: - Configuration options for level and backend.

Examples:

await configureApp({ level: "debug" });

getLogger

Creates a logger for a specific subsystem.

The returned logger automatically adapts if the backend changes after creation (e.g., when {@link configureApp} is called later).

FunctionType
getLogger(subsystem: readonly string[]) => Promise<Logger>

Parameters:

  • subsystem: - Hierarchical category path for the logger.

Returns:

A logger instance scoped to the subsystem.

Examples:

const logger = await getLogger(["faremeter", "client"]);
logger.info("Client initialized", { version: "1.0.0" });

Constants

LogLevels

ConstantType
LogLevelsreadonly ["trace", "debug", "info", "warning", "error", "fatal"]

Interfaces

Logger

PropertyTypeDescription

LoggingBackend

Backend implementation for the logging system.

Backends handle log output destinations (console, file, external service) and can be swapped at runtime via {@link configureApp}.

PropertyTypeDescription

ConfigureAppArgs

Configuration options for initializing the logging system.

PropertyTypeDescription
level"trace" or "debug" or "info" or "warning" or "error" or "fatal" or undefinedMinimum log level to emit. Defaults to "info".
backendLoggingBackend<BaseConfigArgs> or undefinedBackend implementation to use. Auto-detected if not provided.

Types

LogLevel

TypeType
LogLevel(typeof LogLevels)[number]

Context

TypeType
ContextRecord<string, unknown>

LogArgs

TypeType
LogArgs[message: string, context?: Context]

BaseConfigArgs

TypeType
BaseConfigArgs{ level: LogLevel }

License

LGPL-3.0-only

版本与发布记录

@faremeter/logs 共发布 9 个版本,首次发布于 2026/01/29;过去 12 个月发布了 9 个版本。

版本发布日期距今
0.22.0latest2026/05/275 个月前
0.21.02026/04/216 个月前
0.20.12026/04/147 个月前
0.20.02026/04/147 个月前
0.19.02026/03/217 个月前
0.18.02026/03/207 个月前

关于 @faremeter/logs 的常见问题

@faremeter/logs 是什么?

A configurable logging abstraction for Faremeter

如何安装 @faremeter/logs?

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

@faremeter/logs 支持 TypeScript 吗?

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

@faremeter/logs 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@faremeter/logs 可以商用吗?

@faremeter/logs 使用 LGPL-3.0-only 许可。弱 Copyleft:作为库被调用时通常不要求开源你自己的代码,但修改库本身需以 LGPL 开源;前端打包合并后的适用边界存在不同理解。以上为概括,不构成法律意见,请以许可原文为准。

@faremeter/logs 的下载量有多少?

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

@faremeter/logs 还在维护吗?

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