gc-json-logger-nestjs
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

Logger for Structured Logging with Asynchronous Context Tracking (Stability: 2 - Stable) to log HTTP traffic in Nest.JS (Express.JS) in GKE

Enables structured logging for Nest.js application running in Google Cloud platform.

NPM Coverage Release License

Installation

npm install --save \
  gc-json-logger \
  gc-json-logger-express \
  gc-json-logger-nestjs

yarn add \
  gc-json-logger \
  gc-json-logger-express \
  gc-json-logger-nestjs

View in Google Cloud Monitoring

Google Cloud Monitoring

Usage

Demo

Shell

git clone https://github.com/igrek8/gc-json-logger-nestjs
cd gc-json-logger-nestjs
npm install
npm run dev

Log Structure

{"severity":"INFO","time":"2022-10-08T00:00:00.000Z","message":"Starting Nest application...","logging.googleapis.com/operation":{"id":"app"},"meta":{"context":"NestFactory"}}

{"severity":"INFO","time":"2022-10-08T00:00:00.000Z","message":"LoggerModule dependencies initialized","logging.googleapis.com/operation":{"id":"app"},"meta":{"context":"InstanceLoader"}}

{"severity":"INFO","time":"2022-10-08T00:00:00.000Z","message":"AppModule dependencies initialized","logging.googleapis.com/operation":{"id":"app"},"meta":{"context":"InstanceLoader"}}

{"severity":"INFO","time":"2022-10-08T00:00:00.000Z","message":"AppController {/}:","logging.googleapis.com/operation":{"id":"app"},"meta":{"context":"RoutesResolver"}}

{"severity":"INFO","time":"2022-10-08T00:00:00.000Z","message":"Mapped {/trace, POST} route","logging.googleapis.com/operation":{"id":"app"},"meta":{"context":"RouterExplorer"}}

{"severity":"INFO","time":"2022-10-08T00:00:00.000Z","message":"Nest application successfully started","logging.googleapis.com/operation":{"id":"app"},"meta":{"context":"NestApplication"}}

/* HTTP log and LoggerService use the same UUID in "logging.googleapis.com/operation" */

Use with jq

node ./server.js | jq -r '."logging.googleapis.com/operation".id as $id | { time, severity, $id, message } | join(" ")'

Trace Request-Response cycle

Trace-NestJS module adds X-Request-ID and X-Response-ID headers that match operation id.

Package Sidebar

Install

npm i gc-json-logger-nestjs

Weekly Downloads

2,262

Version

2.2.0

License

MIT

Unpacked Size

43.4 kB

Total Files

43

Last publish

Collaborators

  • igrek8