0
0
NestJSframework~30 mins

Logging with Winston or Pino in NestJS - Mini Project: Build & Apply

Choose your learning style9 modes available
Logging with Winston in NestJS
📖 Scenario: You are building a simple NestJS application that needs to log important messages. Logging helps you track what your app is doing and find problems quickly.We will use Winston, a popular logging library, to add logging to your app.
🎯 Goal: Learn how to set up Winston logging in a NestJS app. You will create a logger, configure it, use it to log messages, and see the output in the console.
📋 What You'll Learn
Create a Winston logger instance with console transport
Add a log level configuration variable
Use the logger to log an info message
Print the logged message output
💡 Why This Matters
🌍 Real World
Logging is essential in real apps to track events and errors. Winston is a popular tool for this in Node.js and NestJS apps.
💼 Career
Understanding how to set up and use logging libraries like Winston is a key skill for backend developers and DevOps engineers to monitor and debug applications.
Progress0 / 4 steps
1
Create a Winston logger instance
Create a constant called logger and set it to a Winston logger instance using winston.createLogger with a console transport.
NestJS
Need a hint?

Use winston.createLogger and add new winston.transports.Console() inside the transports array.

2
Add a log level configuration
Create a constant called logLevel and set it to the string 'info'. Then add level: logLevel to the logger configuration.
NestJS
Need a hint?

Define const logLevel = 'info' and add level: logLevel inside the logger options.

3
Log an info message using the logger
Use logger.info to log the message 'NestJS app started'.
NestJS
Need a hint?

Call logger.info with the exact message 'NestJS app started'.

4
Run and see the logged output
Run the program and observe the console output showing the info log message.
NestJS
Need a hint?

Run the file with node and check the console for the log message starting with info:.