javascript - NodeJS - 日志记录 - 日志记录中的请求或堆栈号

标签 javascript node.js logging stack

有 2 个请求到达 Nodejs。两者都阻止请求。

我想使用请求号进行记录,但我找不到任何方式来显示请求号

每个请求调用函数和函数都有日志来调试数据和数据库响应。

- (async) Authenticate Customer ID (function: async checkCumber()) (is Active, is Paid)
  - (async) Get Customer By Id (function: async getCustomer())
     - (async) Get Customer Vehicle by Customer Id (function: async getVehicleByCustomerId())
        - (async) Get Vehicle Details by Vehicle Id (function: async getVehicleByVehicleId())

这是两个请求的 console.log() 的输出。

Customer Validated Customer Id "C2" (this log from request-1)

Customer Detail found from DB (this log from request-1)

Customer Validated Customer Id "C4" (this log from request-2)

Customer 2 Vehicle found (this log from request-1)

Customer Detail found from DB (this log from request-2)

Vehicles detail found (this log from request-1)

Customer 2 Vehicle found (this log from request-2)

Vehicles detail found (this log from request-2)

我想要像这样的日志

Request 55: Customer Validated Customer Id "C2"

Request 55: Customer Detail found from DB

Request 56: Customer Validated Customer Id "C4"

Request 55: Customer 2 Vehicle found

Request 56: Customer Detail found from DB

Request 55: Vehicles detail found

Request 56: Customer 1 Vehicle found

Request 56: Vehicles detail found

通常,我们使用 Java 代码在日志中写入线程号,以便在从生产中获取日志时轻松跟踪问题和调试代码。

如果有任何工具或 npm 包向我建议,可以提供我想要的日志输出。

最佳答案

你可以进入 continuation-local-storage 或 cls-hooked npm 包。它允许您在整个旅程中跟踪特快请求

https://www.npmjs.com/package/continuation-local-storage

关于javascript - NodeJS - 日志记录 - 日志记录中的请求或堆栈号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58183763/

相关文章:

javascript - 出现键盘时如何在Android中处理网站

javascript - 在用户脚本中使用大型文本文件的最有效方法是什么?

javascript - StatsD 启动错误

coldfusion - 查看coldfusion日志的应用程序

node.js - 如何将 Connect/Express 的记录器输出输出到 Winston?

Xcode - 如何查看构建命令和日志?

javascript - ReactDOM 期望 String 但返回一个 Object

javascript - jQuery 不显示和隐藏标题

javascript - AJAX 调用未收到网络服务器的响应

ios - 无法使基本的 socket.io 发出与 Swift 一起工作