Introduction to Logging
Learn how to add logging into the NestJS application.
Suppose our virtual library grows and becomes popular daily, and countless users browse our books catalog, relying on our API. However, the unexpected happens on a hectic day, coinciding with the launch of a highly anticipated novel. The system starts behaving erratically, and users report slow search results. The problem is elusive, users are frustrated, and the reputation of our virtual library hangs in the balance.
Amid this chaos, our team realizes the critical need for a robust solution to quickly identify and understand the root cause of these issues. The solution? A well-structured, efficient logging system. It’s more than just a tool. It’s our eyes and ears within the system, capturing every detail, every request, and every user interaction. In this lesson, we’ll learn how to add a logging system to our application.
Different levels of logs
Before implementing logging in our application, let’s understand the different levels of logs:
-
Verbose
: It’s suitable for providing detailed insights and traceability. It aids in understanding the application flow and behavior in depth. -
Debug
: It’s primarily utilized for development and debugging, offering granular details about the application’s operations. -
Log
: It’s ideal for logging general operational messages that are part of normal application behavior, such as successful task executions. -
Warn
: It’s applied when encountering unexpected yet noncritical events. It serves as an indicator that something requires attention. -
Error
: It’s employed for logging errors or critical issues that impact the application’s operation, usually demanding immediate attention or indicating a failure.