Question: Within a java application, I have several Classes and Threads here and there. I would like them all to write their logs to one single file. How can I achieve that?

Also here's some more questions:

1. Do I receive the same instance of a logger if I define the same name for them even in different classes. To be clear, are the following two loggers the same:

```
class MyClass1 {
    Logger logger1 = Logger.getLogger("theSameName");
}
class MyClass2{
    Logger logger2 = Logger.getLogger("theSameName");
}

```
2. What happens if I define two of the `FileHandler` in two separate Threads that have the same file name?
Do both of them write to the same file?
If yes, what happens if the file is already opened by the first one, when the second one tries to open and write to it?
3. What happens if I try to add the same FielHandler to a logger more than once as in:

```
logger.addHandler(myFileHandler); // in Thread one
...
logger.addHandler(myFileHandler); // in Thread two

```

Will I receive a `RuntimeException` because of the two `FileHandler` may try to open the same file simultaneously?

I'm using `java-util-logging` not `log4j`.

Answer: 
```
package javaloggers;

import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
//singleton class logger wrapper
public class LogWrap {
    public static final Logger aLogger = Logger.getLogger("myLogger");
    private static LogWrap instance = null;
    public static LogWrap getInstance(){
        if(instance==null){
            getLoggerReady();
            instance = new LogWrap();
        }
        return instance;
    }
    private static void getLoggerReady(){
        try{
            FileHandler fh = new FileHandler("test-log.txt");
            fh.setFormatter(new SimpleFormatter());
            aLogger.addHandler(fh);
            aLogger.setUseParentHandlers(false);
            aLogger.setLevel(Level.ALL);
        } catch(Exception e){
            System.out.print("Error: Logger creation issue: "+e);
        }           
    }
}
class test {
    public static void main(String args[]){
        //usage
        LogWrap logWrap = LogWrap.getInstance();
        logWrap.aLogger.severe( "Hello world!" );
    }
}

```
I have code that pushes data to multiple `OutputStreams`. I use it to duplicate `System.out` to both `System.out` and a `FileOutputStream`.

I would basically "reroll" that code so it use multiple input streams to pipe to one "master" file.

Here is my code

```
// This is an OutputStream that duplicate behavior across multiple OutStreams
public class MultiOutputStream extends OutputStream {
  OutputStream[] outputStreams;
  public MultiOutputStream(OutputStream... outputStreams) {
    this.outputStreams = outputStreams;
  }
  @Override
  public void write(int b) throws IOException {
    for (OutputStream out : outputStreams)
        out.write(b);
  }
  @Override
  public void write(byte[] b) throws IOException {
    for (OutputStream out : outputStreams)
        out.write(b);
  }
  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    for (OutputStream out : outputStreams)
        out.write(b, off, len);
  }
  @Override
  public void flush() throws IOException {
    for (OutputStream out : outputStreams)
        out.flush();
  }
  @Override
  public void close() throws IOException {
    for (OutputStream out : outputStreams)
        out.close();
  }
}

```