From bb075c0980d1640ec6201fe7b41fd659ee7a2d9f Mon Sep 17 00:00:00 2001 From: KN-CY Date: Wed, 15 Mar 2023 21:14:39 +0800 Subject: [PATCH] Edit Storage class logging --- .../java/seedu/rainyDay/modules/Storage.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/rainyDay/modules/Storage.java b/src/main/java/seedu/rainyDay/modules/Storage.java index 733357675e..760a85afbb 100644 --- a/src/main/java/seedu/rainyDay/modules/Storage.java +++ b/src/main/java/seedu/rainyDay/modules/Storage.java @@ -7,13 +7,17 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.logging.FileHandler; import java.util.logging.Level; +import java.util.logging.LogManager; import java.util.logging.Logger; public class Storage { - private static Logger logger = Logger.getLogger("StorageLog.log"); + private static Logger logger = Logger.getLogger("Storage.log"); + public static void writeToFile(FinancialReport statements, String filePath) { + setupLogger(); try { FileOutputStream writeData = new FileOutputStream(filePath); ObjectOutputStream writeStream = new ObjectOutputStream(writeData); @@ -38,8 +42,18 @@ public static FinancialReport loadFromFile(String filePath) readStream.close(); readData.close(); - logger.log(Level.INFO, "File read and closed."); return statements; } + + private static void setupLogger() { + LogManager.getLogManager().reset(); + logger.setLevel(Level.INFO); + try { + FileHandler fileHandler = new FileHandler("Storage.log"); + logger.addHandler(fileHandler); + } catch (Exception e) { + logger.log(Level.SEVERE, "File logger not working.", e); + } + } }