0
0
NestJSframework~10 mins

Logging with Winston or Pino in NestJS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Logging with Winston or Pino
Start Application
Initialize Logger (Winston or Pino)
Application Runs
Log Event Occurs
Logger Formats Message
Logger Outputs to Console/File
Continue Application or Exit
The app starts, sets up the logger, then logs messages during runtime, formatting and outputting them as configured.
Execution Sample
NestJS
import { Logger } from '@nestjs/common';
const logger = new Logger('App');
logger.log('App started');
logger.error('Error happened');
logger.warn('Warning issued');
This code creates a NestJS logger and logs messages of different levels.
Execution Table
StepActionLogger MethodMessageOutput FormatOutput Destination
1Initialize LoggerN/AN/ADefault NestJS formatConsole
2Log info messagelogApp started[LOG] [App] App startedConsole
3Log error messageerrorError happened[ERROR] [App] Error happenedConsole
4Log warning messagewarnWarning issued[WARN] [App] Warning issuedConsole
5Application continues runningN/AN/AN/AN/A
💡 Logging completes for these messages; application continues running.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
loggerundefinedLogger instance createdLogger instance usedLogger instance usedLogger instance used
Key Moments - 2 Insights
Why do different logger methods like log, error, and warn produce different output formats?
Each method corresponds to a log level that prefixes the message with its level (e.g., [LOG], [ERROR]), as shown in execution_table rows 2, 3, and 4.
Does the logger stop the application after logging an error?
No, logging an error only outputs the message; the application continues running as shown in step 5 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output format when logger.warn is called?
A[WARN] [App] Warning issued
B[ERROR] [App] Warning issued
C[INFO] [App] Warning issued
DWarning issued
💡 Hint
Check row 4 under Output Format in the execution_table.
At which step does the logger instance get created?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the Action column in the execution_table for initialization.
If you add a logger.debug('Debug info') call, what would change in the execution_table?
AThe existing rows would change their output format
BA new row with Logger Method 'debug' and output format '[DEBUG] [App] Debug info' would appear
CThe logger instance would be recreated
DNo change would happen
💡 Hint
Adding a new log call adds a new row with that method and message.
Concept Snapshot
NestJS logging uses Logger class.
Create logger with new Logger('Context').
Use methods: log(), error(), warn(), debug() for levels.
Messages show level and context.
Outputs go to console or files if configured.
Logging does not stop app execution.
Full Transcript
This visual execution shows how NestJS logging works with Winston or Pino. First, the application starts and initializes a logger instance. Then, during runtime, the logger logs messages at different levels: info, error, and warning. Each log method formats the message with a level prefix and context name. The output goes to the console by default. Logging messages do not stop the application from running. This trace helps beginners see how logging calls translate into formatted outputs step-by-step.