Like many developers, I started a "small" project whose backend I wrote in node.js & express, And for debugging I used simple console.log statements. After all, who needs a logging library for a few API endpoints, right? 😅
Fast forward three months, and that "small" project evolved into something much bigger. New features were rolling in, the complexity grew, and suddenly, those console.log statements weren't cutting it anymore.
Debugging became a nightmare!
🛠️ Entering the “Morgan” Package
My first step into proper logging began with Morgan. It was perfect for HTTP request logging and helped me understand:
- Which routes were being hit
- Response times
- Status codes
- Request methods
But as the application grew further, I needed more...
📈 Leveling Up with “Winston” Package
That's when I discovered Winston, and it was a game-changer! Now I could:
- Create multiple log files for different severity levels
- Format logs with timestamps and custom labels
- Log database operations separately from application errors
- Rotate log files automatically
🧠 What I Learnt
-
Never underestimate how quickly a "small" project can grow. Starting with proper logging early on can save hours of debugging headaches later!
-
In any production system, logging is your eyes and ears into the application's behavior. From tracing API requests and catching database operation failures to monitoring external service responses and tracking business logic errors, a proper logging strategy with tools like Winston helps you understand exactly what's happening in your system.
-
Suppose, any critical error occurs at 2 AM, you'll be grateful for those detailed logs showing the exact flow of execution and where things went wrong.
-
For medium-large scale projects Winston is a must have logging package (for node.js). Earlier I used to read the server errors and go through the API flow but after setting up winston and adding logging on all critical places which can throw errors(specially database operations), I effectively minimized my debugging time.