Search⌘ K
AI Features

Adding Request Logging via Middleware

Explore how to implement request logging in a Deno web application by using middleware to capture HTTP method, request path, and response time. Understand middleware stacking and how logging integrates with other middleware for effective monitoring. This lesson prepares you to add consistent request logs throughout your application.

We'll cover the following...

In this lesson, we’ll use the middleware we created previously and add logic to log what request is being made to the server.

Now that we have the logic to calculate the request timing we’ve built, we’re in a great place to add request logging to our application. The final goal is to have every request that is made to the application logged to the console with its path, HTTP method, and the time it took to answer. We’re looking for something like the following example:

GET http://localhost:8080/api/museums - 65ms

We could, of course, do this individually per request, but since this is something that we want to do cross-application, we’ll add it as a piece of middleware to the Application object.

The middleware we wrote previously requires the ...