title: Log4j multiple log files and logging in common code
body: <p>I have to log to separate log files depending on the service being used. So lets say I have service1 &amp; service2 and the logs are going to service1.log &amp; service2.log respectively.</p>
  
  <p>The issue is that there is some common code being used from both the services. Now how do I make the logs such that if the common code is called by any of the service then log into that specific log file.</p>
  
  <p>The way I am create the logger is</p>
  
  <pre><code>private static final Logger logger = Logger.getLogger(ClassName.class);
  </code></pre>
  
  <p>The way I am thinking to handles this is by passing a string (logger name) to the common code and creating the logger at the method level instead of class.</p>
  
  <p>Example:</p>
  
  <pre><code>someMethodInCommonCode(String loggerName) {
    Logger logger = Logger.getLogger(loggerName);
  }
  </code></pre>
  
  <p>I have read that log4j maintains a cache of loggers so create a logger in method won't be a overhead I guess.</p>
  
  <p>And yes I don't like logger name being passed. So is there a way or any configuration by which I can achieve the above scenario or any other ideas.</p>