Structured Application Logging with Winston
Learn how to add structured, professional-grade logging to your Express app using Winston.
Logging is often an afterthought—until something breaks in production and we have no clue why.
Effective logging is mission-critical for complex apps. It’s how we track user behavior, catch bugs, measure performance, and troubleshoot—sometimes weeks after they occur. While console.log()
works during development, it doesn’t scale in real-world applications. That’s where structured logging and a battle-tested library like Winston come in.
We can use Winston to log across all parts of our application—from incoming HTTP requests to background jobs and database operations—and even forward those logs to external monitoring tools.
What are structured logs?
Structured logs are machine-readable (often in JSON) and include rich context such as timestamps, user IDs, and request details. This makes them easy to index, filter, and search in log management systems.
In contrast, console.log()
produces plain, unstructured text, which is harder to parse, search, or use effectively at scale.
Let’s see how Winston enables this kind of structured logging with ease.
Setting up Winston in an Express app
We’ll begin by creating a reusable logger module using Winston. This logger can then be imported across our app wherever we need to log something.
Get hands-on with 1400+ tech skills courses.