@flatfile/utils-debugger

中文文档
0.0.6发布于 2024/05/02ISCTypeScriptESM + CJS近 30 天下载 11.3万

A helper for logging useful messages to the console

原始使用文档
文档目录10 节
  1. Features
  2. Usage
  3. logHttpRequest(params)
  4. logEventSubscriber(query, filter)
  5. logEvent(event)
  6. logWarning(message), logSuccess(message), logError(message,…
  7. log(callback)
  8. Installation
  9. Dependencies
  10. Examples

@flatfile/utils-debugger

This package is a utility debugger designed to facilitate the tracking, logging and debugging of various events, issues and processes in your application. It features a colorful console output for better visibility and understanding of the status of your system.

Features

  • HTTP request logging
  • Event subscription logging
  • Event logging
  • Logging for warnings, success, and errors
  • General purpose logging

Usage

The @flatfile/utils-debugger package provides a Debugger class which exposes several static methods. Each of these methods are designed to log specific types of events or issues.

Here is a brief overview of the available methods:

logHttpRequest(params)

Logs details about HTTP requests. It takes an object with the following properties:

  • method: The HTTP method (GET, POST, PUT, DELETE, etc.)
  • url: The request URL.
  • statusCode: The HTTP status code.
  • headers: The request headers.
  • startTime: The time when the request started.
  • error (optional): Any error that occurred during the request.

The log includes the method, status code, URL, and time elapsed since the start of the request.

  ✓ 100ms      GET     200 https://example.com

logEventSubscriber(query, filter)

Logs details about an event subscriber.

  • query: The query or array of queries the subscriber is listening for.
  • filter: The filter applied to the subscriber (optional).
 ↳ on(user.created), {}

logEvent(event)

Logs details about a given event.

  • event: The event object to log. It must have topic, createdAt, and id properties.
 ▶ user.created 5:58:30.572 PM 4hs98r

logWarning(message), logSuccess(message), logError(message, label, prefix)

Logs warnings, successes, and errors.

  • message: The message to log.
  • label and prefix are optional parameters for the logError function.
  ⚠️ Disk space running low
  ✅ File uploaded successfully
  🔴 Error:FileError File not found

log(callback)

A general purpose log method, it accepts a callback function that returns the string to log. The callback receives a colors object that you can use to apply color to parts of your message.

Installation

To install the @flatfile/utils-debugger package, use npm or yarn:

npm install @flatfile/utils-debugger

or

yarn add @flatfile/utils-debugger

Dependencies

This package has a dependency on the ansi-colors package for coloring console output.

Examples

import { Debugger } from '@flatfile/utils-debugger'

Debugger.logHttpRequest({
  method: 'GET',
  url: 'https://example.com',
  statusCode: 200,
  headers: {},
  startTime: Date.now(),
})

Debugger.logEventSubscriber('user.created')

Debugger.logEvent({
  topic: 'user.created',
  createdAt: new Date(),
  id: 'abcd1234',
})

Debugger.logWarning('Disk space running low')

Debugger.logSuccess('File uploaded successfully')

Debugger.logError('File not found', 'FileError', 'Upload')

版本与发布记录

@flatfile/utils-debugger 共发布 7 个版本,首次发布于 2023/06/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.6latest2024/05/022 年前
0.0.52023/07/183 年前
0.0.42023/06/133 年前
0.0.32023/06/103 年前
0.0.22023/06/073 年前
0.0.12023/06/073 年前

关于 @flatfile/utils-debugger 的常见问题

@flatfile/utils-debugger 是什么?

A helper for logging useful messages to the console

如何安装 @flatfile/utils-debugger?

在项目目录运行 npm install @flatfile/utils-debugger,或使用 pnpm add / yarn add / bun add。

@flatfile/utils-debugger 支持 TypeScript 吗?

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

@flatfile/utils-debugger 支持 ESM 还是 CommonJS?

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

@flatfile/utils-debugger 可以商用吗?

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

@flatfile/utils-debugger 的下载量有多少?

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

@flatfile/utils-debugger 还在维护吗?

最新版本 0.0.6 发布于 2024/05/02(2 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/06/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。