Class HttpLoggingUtilities


  • public class HttpLoggingUtilities
    extends Object
    • Constructor Detail

      • HttpLoggingUtilities

        public HttpLoggingUtilities()
    • Method Detail

      • isValidPublicIp

        protected static boolean isValidPublicIp​(String ip)
        From http://codereview.stackexchange.com/a/65072
        Parameters:
        ip - IP to check
        Returns:
        true if IP is a valid public IP
      • anonymizeIp

        protected static String anonymizeIp​(String ip)
      • addRequestClientInfoToMDC

        public static void addRequestClientInfoToMDC​(javax.servlet.http.HttpServletRequest request)
        Puts http request infos (client infos) to MDC logging context. Make sure to clear MDC after logging! Using MDC instead of LogstashMarker, because otherwise we drag in logging implementation logstash as dependency. We care for having no other logging dependency than slf4j.

        Usage example:

         HttpLoggingUtilities.addRequestClientInfoToMDC(request);
         MDC.put("collection name", name);
         try {
           Collection collection = presentationService.getCollection(name);
           LOGGER.info("Serving collection for {}", name);
           return collection;
         } catch (NotFoundException e) {
           LOGGER.info("Did not find collection for {}", name);
           throw e;
         } catch (InvalidDataException e) {
           LOGGER.info("Bad data for {}", name);
           throw e;
         } finally {
           MDC.clear();
         }
         
        Parameters:
        request - http request object containing info