Reputation: 197
I have a Springboot REST API hosted in Tomcat. The client sends get requests in following format
hostname.com/MyAPI/GetProduct/{productId}
hostname.com/MyAPI/GetCategory/{categoryId}
There are 5 of such APIs being used.
Tomcat AccessLogValve logs all these records with parameters (productId, categoryId). When I try to analyse these logs using AWStats it is unable to understand that /GetProduct/001 and /GetProduct/002 are same API endpoints.
As of now I have found two probable solutions for this
Update AWStats perl scripts to understand they are same and ignore the parameters (I have least knowledge of perl)
Create a custom AccessLogValve to remove the last part of url in logs. This is more appropriate for me.
Is it possible to do such thing using option 2. Any sample github link shall be appreciated.
Tried below code but seems this has some wrong assumptions about the method being overridden.
`package com.example;
import org.apache.catalina.valves.AccessLogValve;
import javax.servlet.http.HttpServletRequest;
public class CustomAccessLogValve extends AccessLogValve {
@Override
protected void log(HttpServletRequest request, String value) {
String fullPath = request.getRequestURI();
// Extract the first 3 parts of the path
String[] parts = fullPath.split("/");
StringBuilder firstThreeParts = new StringBuilder();
// Ensure we don't go out of bounds
for (int i = 0; i < Math.min(3, parts.length); i++) {
firstThreeParts.append("/").append(parts[i]);
}
// Log only the first 3 parts of the path
super.log(request, firstThreeParts.toString());
}
} `
Upvotes: 0
Views: 6