Exercise: Logging with Middleware

Practice how to create the logging component using the Middleware pattern.

Problem statement

Rewrite the logging component you implemented for “Exercise: Logging with Stretegy” and “Exercise: Logging with Template”, but this time use the Middleware pattern to postprocess each log message allowing different middlewares to customize how to handle the messages and how to output them. We could, for example, add a serialize() middleware to convert the log messages to a string representation ready to be sent over the wire or saved somewhere. Then, we could add a saveToFile() middleware that saves each message to a file. This exercise should highlight the flexibility and universality of the Middleware pattern.

Coding challenge

Write your solution code in the following code widget. We’ve already added the package.json file for your ease.

Get hands-on with 1200+ tech skills courses.