I have a java application which has 'hypotetically speaking' 3 objects... 1 of the class Animal, 1 of the class Food, those are not related by any inheritance or interface..and a last one of the class Manager wich is having a list of animals and list of Food, the manager is responsable for a zoo where those animals and Food are..
to the point...
Am using log4j and I need to log to the a txt file IF ONLY AND ONLY IF something in the animal list changes... (animal dies, borns or what ever...) and I need to log to the System.out IF AND ONLY IF something in the Food list changes... (new food is need, food was eaten, what ever...)
My question:
How can I do that with log4j?
I have found here: Log4j : Creating/Modifying appenders at runtime, log file recreated and not appended
something like dynamically changing the appender
String targetLog="where ever you want your log"
FileAppender apndr = new FileAppender(new PatternLayout("%d %-5p [%c{1}] %m%n"),targetLog,true);
logger.addAppender(apndr);
logger.setLevel((Level) Level.ALL);
but I think this is very ugly and error prone to add and remove the appender constantly all over the hole application..
Is there any better way to handle this can I have 2 logger (one for animals 1 for the food)??
any suggestion??
Thanks