Default NestJS Logger and Custom Logger

Learn and practice using the NestJS logger and custom loggers.

Logging is essential in NestJS applications. It helps us to troubleshoot and debug, track the application flow, and create an audit trail.

In NestJS, a default logging feature is provided out of the box, and we also have the flexibility to create custom loggers. In this lesson, we’ll explore using the default logger and then create custom loggers tailored to our application’s requirements.

Default loggers

NestJS provides a default logger. The default logger can output log messages to the console, making it easier for developers to track the application flow and log errors. The default logger is simple and easy to use, so it’s a good starting point for logging with NestJS.

Use the default logger

NestJS exposes a Logger class via the @nestjs/common package. The Logger class provides a corresponding method for each of the log levels.

We need to create a new instance to use it.

Get hands-on with 1200+ tech skills courses.