From the course: Node.js: Debugging and Performance Tuning
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Request logging with Morgan
From the course: Node.js: Debugging and Performance Tuning
Request logging with Morgan
- [Instructor] It's good to avoid reinventing the wheel, and we made a pretty square one a couple of videos ago when we used the console to log requests. As we saw, it worked, but it wasn't optimal. Is there a better solution? Yes, and it's called morgan. Morgan is a no-JS HTTP request logger middleware which supports servers including Express. When logging, morgan includes a number of details about the HTTP method, path requested, and content length. Morgan logs once the request is sent so it can include the HTTP status code and response time, which is really useful for debugging and finding slow performance. Optionally, morgan can also include the referrer and user agent strain. Morgan can be used with most loggers, including Winston. Morgan provides some very convenient logging format defaults including the standard Apache combined log output. It also provides a system of token replacements so you can easily create your own, or customize it. We're going to replace our console…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Why and what should I log?6m 26s
-
Problems with Node.js console6m 1s
-
(Locked)
Implementing Express error pages6m 48s
-
(Locked)
Choosing a logging library5m 40s
-
(Locked)
Adding Winston for Node logging4m 41s
-
(Locked)
Request logging with Morgan6m 39s
-
(Locked)
Correlating requests in logs6m 18s
-
(Locked)
Cross-application request correlation5m 32s
-
(Locked)
Challenge: Cross-application request IDs2m 14s
-
(Locked)
Solution: Cross-application request IDs9m 30s
-
(Locked)
-
-
-