Skip to content

Commit

Permalink
Merge pull request #94 from KN-CY/edit-logging-Storageclass
Browse files Browse the repository at this point in the history
Edit Storage class logging
  • Loading branch information
lil1n authored Mar 15, 2023
2 parents 92141bf + bb075c0 commit 462c23b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/seedu/rainyDay/modules/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
}

0 comments on commit 462c23b

Please sign in to comment.