Implementing Zuul Logging Filter
In the previous section, we have discussed common functionality that is implemented in API Gateway. We have the Zuul server ready that acts as API Gateway.
In this section, we will implement the logging functionality in the Zuul API Gateway.
Let's implement the logging in the Zuul API Gateway.
Step 1: In the netflix-zuul-api-gateway-server project, create a new class file with the name ZuulLoggingFilter.
Step 2: Add an annotation @Componenet.
Step 3: Extend the ZuulFilter class. There are some abstract methods in the ZuulFilter class. These abstract methods must be implemented in the ZuulLoggingFilter class.
Step 4: Move your cursor over the ZuulLoggingFilter class. It suggests two quick fixes, as shown in the following image. Click on the Add unimplemented methods. We get the default implementation of all the abstract methods of the ZuulFilter class.
ZuulFilter class has four abstract methods that are listed below:
Step 5: Create the Logger class object and invoke getLogger() method to create a logger.
Remember: Import Logger class of org.slf4j package.
Step 6: Implement the logic in the run() method.
In the next step, we will see how to intercept the request using Zuul.