title: How to generate unique request id for each log4j request
body: <p>I am printing log of request and response by using log4j. I want to assign a unique ID to each request and same ID to its response, there are multiple requests so it will be easier for me to identify each request and response.</p>
  
  <p>This is what i was using, but its not working. Its updating the UDID on response as well.</p>
  
  <pre><code>    public void logRequestObject(HttpServletRequest httprequest){
      uniqueID= UUID.randomUUID().toString();          
      logger.info("Log4J - "+ "Request: requestId= "+ uniqueID+  ",Headers= "+ map);  
  }
  
      public void logResponseObject(HttpServletResponse httpResponse){    
        logger.info("Log4J - "+ "Response: ,requestId= " + uniqueID + " ,responseTime= " + " totalTime= "+ totalTime);        
  }
  </code></pre>
  
  <p>Then i came to know that log4j provides a way to record unique ID to each request.</p>
  
  <p>I have read many posts on stackoverflow, but still unable to understand it.</p>
  
  <p>This is my <code>properties</code> files.</p>
  
  <pre><code># Root logger option
  log4j.rootLogger=INFO, stdout, file, CATALINA
  
  # Catalina
  
      log4j.appender.CATALINA=org.apache.log4j.RollingFileAppender
      log4j.appender.CATALINA.File=${catalina.home}/logs/catalina.out
      log4j.appender.CATALINA.MaxFileSize=10MB
      log4j.appender.CATALINA.MaxBackupIndex=5
      log4j.appender.CATALINA.layout=org.apache.log4j.PatternLayout
      log4j.appender.CATALINA.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss}  %X{RequestId} %p-%c{1}: [%m]%n
      log4j.appender.CATALINA.Append=true
      log4j.appender.CATALINA.Encoding=UTF-8
  </code></pre>