diff --git a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/LogUtils.java b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/LogUtils.java index a256c1044b7a..7466dc66e9a4 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/LogUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/LogUtils.java @@ -127,16 +127,20 @@ protected static String getMatchingLogLevel(MessageContext ctx, Map entry : logProperties.entrySet()) { - String key = entry.getKey().substring(1); - if (apiCtx.startsWith("/" + key) || apiCtx.equals(key)) { - ctx.setProperty(LogsHandler.LOG_LEVEL, entry.getValue()); - ctx.setProperty("API_TO", apiCtx); - return entry.getValue(); + TreeMap selectedAPIS = Utils.getSelectedAPIList(path, tenantDomain); + if (selectedAPIS.size() > 0) { + String selectedPath = (String) selectedAPIS.firstKey(); + API searchedAPI = (API) selectedAPIS.get(selectedPath); + if (searchedAPI != null) { + String apiCtx = searchedAPI.getContext(); + for (Map.Entry entry : logProperties.entrySet()) { + String key = entry.getKey().substring(1); + if (apiCtx.startsWith("/" + key) || apiCtx.equals(key)) { + ctx.setProperty(LogsHandler.LOG_LEVEL, entry.getValue()); + ctx.setProperty("API_TO", apiCtx); + return entry.getValue(); + } + } } } return null;