public static void log(String msg){
Logger logger = Logger.getLogger("MyLog");
FileHandler fh;
try {
boolean append = true;
string filePath = "actions.log";
File file = new File(filePath );
// This block configure the logger with handler and formatter
fh = new FileHandler(filePath ,append);
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
// the following statement is used to log any messages
logger.info(msg);
} catch (SecurityException e) {
// log(e.getMessage());
} catch (IOException e) {
// log(e.getMessage());
}
}
Comments
Post a Comment