Lesson 78/100

Tutorials MEAN Stack Tutorial

Logging — Complete Guide

Logging — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MEAN Stack Tutorial on Toolliyo Academy.

On this page

MEAN Stack Tutorial · Lesson 78 of 100

Logging

Stack ✓Projects

Projects · 2 — Apps · ~10 min · MEAN — Performance & Testing

What is this?

Structured logging records JSON events — level, message, correlationId, userId — from MeanVerse Express and Angular errors.

Why should you care?

grep plain text in prod is hopeless; structured logs feed Elasticsearch and alerts.

See it live — copy this example

Paste into your MeanVerse project (Angular + Express + MongoDB), then run with ng serve / node / mongosh as noted.

import pino from 'pino';
import pinoHttp from 'pino-http';

const logger = pino({ level: process.env.LOG_LEVEL ?? 'info' });
app.use(pinoHttp({ logger, genReqId: req => req.headers['x-request-id'] ?? crypto.randomUUID() }));

logger.info({ event: 'transfer_posted', transferId, tenantId, amountCents }, 'Transfer completed');

// Angular global error handler
@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
  handleError(error: unknown) {
    this.log.error({ source: 'angular', error: String(error) });
  }
}

What happened?

  • pino outputs JSON one line per log.
  • pinoHttp adds req id per request.
  • Include domain fields for search.
  • Angular reports client errors to same pipeline.

Practice next

  1. Replace console.log with pino in API.
  2. Pass x-request-id from Nginx through stack.
  3. Redact passwords and tokens in serializers.
  4. Add child logger with tenantId bound per request.
  5. Log slow queries over 200ms threshold.

Remember

Structured JSON logs searchable at scale. Correlation id ties Angular to API lines. Redact secrets and sensitive fields.

Production incident

Transfers fail for one tenant only.

Outcome: Filter tenantId in Kibana finds validation bug in 3 minutes.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain JavaScript in the context of MEAN Stack.
Short answer: JavaScript runs single-threaded with an event loop. Closures capture lexical scope; promises/async handle I/O without blocking the UI thread. Real-world example (ShopNest) On the ShopNest storefront UI, thi…
Mid Detailed
What are common mistakes teams make with Components when using MEAN Stack?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Component…
Senior Detailed
How would you debug a production issue related to State in a MEAN Stack application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define State in…
Junior Detailed
Describe a real-world scenario where Performance mattered in a MEAN Stack project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Performan…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

MEAN Stack Tutorial
Course syllabus

MEAN Tutorial

MEAN — Stack Foundations
MEAN — Fundamentals
MEAN — TypeScript & RxJS
MEAN — Node.js & Express
MEAN — & Databases
MEAN — Authentication & Security
MEAN — Real-Time & Advanced Systems
MEAN — Performance & Testing
MEAN — DevOps & Deployment
MEAN — Enterprise Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details