Reputation: 1053
I'm writing a log file in my Java program using the code from here
public static void main(String[] args) {
Logger logger = Logger.getLogger("MyLog");
FileHandler fh;
try {
// This block configure the logger with handler and formatter
fh = new FileHandler("C:/temp/test/MyLogFile.log");
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
// the following statement is used to log any messages
logger.info("My first log");
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
logger.info("Hi How r u?");
}
My problem is that i'm getting a multiple log files
Upvotes: 0
Views: 365
Reputation: 587
Change the code as below
fh = new FileHandler("C:/temp/test/MyLogFile.log", true);
This will not create multiple files and will append to the same file.
Upvotes: 2