• Post Reply Bookmark Topic Watch Topic
  • New Topic

can I use a single java.util.logging.logger instance for entire project  RSS feed

 
Surajsingh Thakur
Ranch Hand
Posts: 124
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can I use a single java.util.logging.logger instance for entire project
Actually we can use this logger like this:
LOGGER = Logger.getLogger(SencitivitySpecificityBase.class.getName());
but this logger is for a specific class.
I want to use a single logger for the entire class.
static {

LOGGER = Logger.getLogger(SencitivitySpecificityBase.class.getName());
FileHandler fh;
try {

// This block configure the logger with handler and formatter
fh = new FileHandler("CCVDev.log", true);
LOGGER.addHandler(fh);
LOGGER.setLevel(Level.ALL);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);

// the following statement is used to log any messages
//LOGGER.log(Level.WARNING,"My first log");

} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.

but this logger is for a specific class.
I want to use a single logger for the entire class.

Er... you mean entire application?

Sure, you could--but why? It removes the ability to selectively set logging levels, and get information about where the log message is coming from. Seems like a huge step backwards; might as well just use printlns.
 
Gokul Nanthakumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically speaking you can use same instance for the entire project, but as David Said you are going backwards. do you see any specific advantage in this approach like performance improvement etc., Actually you are loosing control over the logging in using single instance for the whole application
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!