Why is the new instance using the registrar from the old instances?
I am generating 2 instances this way:
gameManager manager1 = new CTManager(owner,players1,"en");
manager1.start();
gameManager manager2 = new CTManager(owner,players2,"en");
manager2.start();
The start()
gameManager method looks like this:
void start() {
game.start();
}
When I instantiate the game, I create loger: log = Logger.getLogger("TestLog");
( log
is the public field of the class it belongs to game
).
In game.start()
I start many processes and give them a link to the corresponding one log
. So I expect manager1 and manager2 to write to different files. But manager2 writes to its file and to manager1's log file. Why might this happen?
a source to share
Assuming you are using Log4J or java.util.logging (which is based on Log4J) there will only be one registered per class / name. No matter how many times you call a method getLogger
with the same argument, it will return exactly the same object to you.
Therefore, when you call getLogger("TestLog")
on each of your instances, you will get a reference to the same object Logger
. Hence, it will only log in one place, the one configured for the "TestLog" logger.
If you want the output from these two instances to go to different locations, you will need to call them getLogger
with different arguments so that they can receive different loggers (and of course, set up the logging system so that the two loggers have different outputs).
a source to share