Java: How to make two loggers write in different files (Logger)
<p>I have 2 loggers in the same class, set up like this:</p>

<pre><code>Logger logger = Logger.getLogger("MyLog");  
FileHandler fh;  

try {  
    // This block configure the logger with handler and formatter  
    fh = new FileHandler("C:/temp/test/MyLogFile.log");  
    logger.addHandler(fh);
    SimpleFormatter formatter = new SimpleFormatter();  
    fh.setFormatter(formatter);  
    // the following statement is used to log any messages  
    logger.info("My first log");  
} catch (SecurityException e) {  
    e.printStackTrace();  
} catch (IOException e) {  
    e.printStackTrace();  
}  
</code></pre>

<p>The second logger is set up the same way, just as <code>logger2</code> and <code>fh2</code> and <code>MyLogFile2.log</code>.</p>

<p>My problem is that whenever any logger logs, both files are written into, even though I only call one logger e.g. <code>logger2.log(Level.INFO, "msg2")</code>.</p>

<p>Why is that? Is it because both loggers are open at the same time? But I do not want to .close()/create them each time I use them. Any better solution?</p>