简体   繁体   English

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

[英]NodeJS - Logging - Request or Stack number in logging

There 2 requests reaching to nodejs.有 2 个请求到达 nodejs。 Both are blocking requests.两者都在阻止请求。

I want to logs with request number I do not find any way to present request number我想用请求号记录我找不到任何方法来提供请求号

Each request call functions and functions have logs to debug data and DB response.每个请求调用函数和函数都有日志来调试数据和数据库响应。

- (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())

Here is the output of console.log() of both requests.这是两个请求的 console.log() 的 output。

Customer Validated Customer Id "C2" (this log from request-1)客户验证的客户 ID“C2”(来自 request-1 的此日志)

Customer Detail found from DB (this log from request-1)从数据库中找到客户详细信息(此日志来自 request-1)

Customer Validated Customer Id "C4" (this log from request-2)客户验证的客户 ID“C4”(来自 request-2 的此日志)

Customer 2 Vehicle found (this log from request-1)找到客户 2 车辆(此日志来自 request-1)

Customer Detail found from DB (this log from request-2)从 DB 中找到的客户详细信息(来自 request-2 的此日志)

Vehicles detail found (this log from request-1)找到车辆详细信息(此日志来自 request-1)

Customer 2 Vehicle found (this log from request-2)找到客户 2 车辆(此日志来自 request-2)

Vehicles detail found (this log from request-2)找到车辆详细信息(此日志来自 request-2)

I want logs like我想要像这样的日志

Request 55: Customer Validated Customer Id "C2"请求 55:客户验证的客户 ID“C2”

Request 55: Customer Detail found from DB请求 55:从 DB 中找到客户详细信息

Request 56: Customer Validated Customer Id "C4"请求 56:客户验证的客户 ID“C4”

Request 55: Customer 2 Vehicle found请求 55:找到客户 2 车辆

Request 56: Customer Detail found from DB请求 56:从 DB 中找到客户详细信息

Request 55: Vehicles detail found请求 55:找到车辆详细信息

Request 56: Customer 1 Vehicle found请求 56:找到客户 1 辆车

Request 56: Vehicles detail found请求 56:找到车辆详细信息

Generally, we do with Java code write thread number with log to easy to trace issues and debug code when got logs from production.通常,我们使用 Java 代码编写带有日志的线程号,以便在从生产中获取日志时轻松跟踪问题和调试代码。

If there any tool or npm package suggest to me which gives me my desire log output.如果有任何工具或 npm package 向我建议,这给了我我的愿望日志 output。

you could into continuation-local-storage or cls-hooked npm package.您可以进入 continuation-local-storage 或 cls-hook npm package。 It allows you to track an express request throughout its journey它允许您在整个过程中跟踪快递请求

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM