I use java.util.logging
, and I put the log inside a application managed bean, since I think there should be just one logger for the entire application.
@ManagedBean(name="logging")
@ApplicationScoped
public class Logging {
private static Logger logger = Logger.getLogger(Logger.class.getName());
private static FileHandler fh = null;
public Logging() {
try{
fh = new FileHandler("DMBackingBean");
}catch(IOException ignore){}
logger.addHandler(fh);
logger.setLevel(Level.ALL);
}
public Logger getLogger(){
return logger;
}
}
Here is the strange behavior I run into. When I run the program the first time, I log AAA
inside DMBackingBean
. Then I redeploy the application (new session), now I saw another log file is created, DMBackingBean.1
with content of AAA
. The contain of DMBackingBean
is now
AAA
AAA
Two question: Is it standard to put the logging inside an application scoped bean? Is there a way for me to have all the logs append into one file, instead of every time I redeploy (new session), a new log file is created?