This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.logging.Logger: outputs multiple similar lines

 
Steve Watson
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the new (In jdk 1.4) Logging API, we find that the same message is output to the log multiple times - does anyone know the solution to this?
We have a Logging class that includes:
public class AppLogger{
private Logger logger = null;
public AppLogger(String appClassName, boolean fileLogging){
try{
Context ctx = new InitialContext();
logger = Logger.getLogger(appClassName);
FileHandler handler = null;
if (fileLogging){
handler = (FileHandler) ctx.lookup("AppSoapMsgFileHandler");
} else {
handler = (FileHandler) ctx.lookup("AppFileHandler");
}
logger.addHandler(handler);
logger.setLevel(handler.getLevel());
} catch(NamingException ne){
WLSLogger.info("NamingException occured while looking up AppFileHandler/AppSoapMsgFileHandler: "+ne.getMessage());
}
}
public void configLogger(String logMsg){
logger.config(logMsg);
}
public void infoLogger(String logMsg){
logger.info(logMsg);
}
public void warningLogger(String logMsg){
logger.warning(logMsg);
}
public void severeLogger(String logMsg){
logger.severe(logMsg);
}
Then individual classes invoke logging by instatiating the AppLogger and calling its methods:
private AppLogger logger = new AppLogger(this.getClass().getName(),false);
logger.infoLogger("Hello World");
I appreciate any help.
Steve Watson
 
Steve Watson
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a solution - in case anyone reads this thread I will answer my own problem. Basically need to control instances of the logging class - made it into a Singleton.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic