Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Contextual logging in Node.js with Pino and AsyncLocalStorage

License

NotificationsYou must be signed in to change notification settings

Maximization/contextual-logging-nodejs

Repository files navigation

For a detailed explanation of the concepts used in this repository, read the accompanying article:Logging with Pino and AsyncLocalStorage in Node.js.

An example Node.js (Express) application that implements contextual logging by attaching a request ID to every log line. It usesAsyncLocalStorage together withPino.

Getting started

  1. Clone this repository:
git clone git@github.com:Maximization/contextual-logging-nodejs.git&&cd contextual-logging-nodejs
  1. Install NPM dependencies:
npm install
  1. Start the Node.js application:
npm start
  1. Visithttp://localhost:3000/users/1 in your browser and hit refresh a few times.
  2. View the logs in your terminal. Each log line will have a unique request ID present.
{...,"requestId":"da672623-818b-4b18-89ca-7eb073accbfe","userId":1,"msg":"Fetching user from DB"}{...,"requestId":"da672623-818b-4b18-89ca-7eb073accbfe","user":{...},"msg":"User found, sending to client"}{...,"requestId":"01107c17-d3c8-4e20-b1ed-165e279a9f75","userId":1,"msg":"Fetching user from DB"}{...,"requestId":"01107c17-d3c8-4e20-b1ed-165e279a9f75","user":{...},"msg":"User found, sending to client"}

About

Contextual logging in Node.js with Pino and AsyncLocalStorage

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp