gc-json-logger-nestjs
v2.2.0
Published
Enables structured logging for Nest.js application running in Google Cloud platform
Downloads
6,653
Readme
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.
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
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.