From 0e0b4cf22aacc5df514d3382e2dccb6d4c1f152f Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 10:49:14 +0800 Subject: [PATCH 1/7] Add logger in Parser.java --- src/main/java/seedu/cafectrl/parser/Parser.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index a55c3dde2a..cf644bb55f 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -98,7 +98,7 @@ public Command parseCommand(Menu menu, String userInput, Ui ui, final Matcher matcher = userInputPattern.matcher(userInput.trim()); if (!matcher.matches()) { - logger.warning("Unmatching regex!"); + logger.warning("Unmatched regex!"); return new IncorrectCommand(ErrorMessages.UNKNOWN_COMMAND_MESSAGE, ui); } @@ -150,6 +150,7 @@ public Command parseCommand(Menu menu, String userInput, Ui ui, return prepareShowSalesByDay(arguments, ui, sales, menu); default: + logger.warning(ErrorMessages.UNKNOWN_COMMAND_MESSAGE); return new IncorrectCommand(ErrorMessages.UNKNOWN_COMMAND_MESSAGE, ui); } } @@ -180,6 +181,7 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u // Checks whether the overall pattern of edit price arguments is correct if (!matcher.find()) { + logger.log(Level.WARNING, "Unmatched regex!"); return new IncorrectCommand(ErrorMessages.MISSING_ARGUMENT_FOR_EDIT_PRICE, ui); } @@ -192,7 +194,8 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u String dishIndexText = matcher.group(dishIndexGroup).trim(); // Check whether the index is empty - if (dishIndexText.equals("")) { + if (dishIndexText.isEmpty()) { + logger.warning("Empty dish index!"); return new IncorrectCommand(ErrorMessages.MISSING_DISH_IN_EDIT_PRICE, ui); } @@ -200,15 +203,18 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u // Check whether the dish index is valid if (!menu.isValidDishIndex(dishIndex)) { + logger.warning("Invalid dish index!"); return new IncorrectCommand(ErrorMessages.INVALID_DISH_INDEX, ui); } } catch (NumberFormatException e) { + logger.warning("Invalid dish index type!"); return new IncorrectCommand(ErrorMessages.WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE, ui); } try { newPrice = parsePriceToFloat(matcher.group(newPriceGroup).trim()); } catch (ParserException e) { + logger.warning("Invalid price!"); return new IncorrectCommand(e.getMessage(), ui); } @@ -230,7 +236,7 @@ private static Command prepareAdd(String arguments, Menu menu, Ui ui) { try { // Checks whether the overall pattern of add arguments is correct if (!matcher.matches()) { - logger.log(Level.WARNING, "Unmatching regex!"); + logger.log(Level.WARNING, "Unmatched regex!"); return new IncorrectCommand(ErrorMessages.INVALID_ADD_DISH_FORMAT_MESSAGE + AddDishCommand.MESSAGE_USAGE, ui); } From 6e137b1402c78d838eed63feb8dfd07ec920ad66 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 10:49:27 +0800 Subject: [PATCH 2/7] Add logger in decoder.java --- src/main/java/seedu/cafectrl/storage/Decoder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index b158f49ae4..5a4f51029d 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -95,6 +95,7 @@ private static void checkUnitValidity(String unit) throws Exception { * @return a new pantry object with data from the pantry stock data file */ public static Pantry decodePantryStockData(ArrayList encodedPantryStock) { + logger.info("Decoding Pantry_stock.txt to PantryStock..."); ArrayList pantryStock = new ArrayList<>(); Ingredient ingredient; @@ -102,6 +103,7 @@ public static Pantry decodePantryStockData(ArrayList encodedPantryStock) return new Pantry(ui); } for (String encodedData : encodedPantryStock) { + logger.info("Line to decode: " + encodedData); String[] decodedData = encodedData.split(DIVIDER); if (!isValidPantryStockFormat(decodedData)) { ui.showToUser(ErrorMessages.ERROR_IN_PANTRY_STOCK_DATA); @@ -116,6 +118,7 @@ public static Pantry decodePantryStockData(ArrayList encodedPantryStock) try { qty = Integer.parseInt(qtyText); } catch (NumberFormatException e) { + logger.log(Level.WARNING, "Line corrupted: " + e.getMessage(), e); ui.showToUser(ErrorMessages.ERROR_IN_PANTRY_STOCK_DATA); continue; } @@ -129,6 +132,7 @@ public static Pantry decodePantryStockData(ArrayList encodedPantryStock) ingredient = new Ingredient(ingredientName, qty, unit); pantryStock.add(ingredient); } else { + logger.info(ErrorMessages.ERROR_IN_PANTRY_STOCK_DATA); ui.showToUser(ErrorMessages.ERROR_IN_PANTRY_STOCK_DATA); } } From efc3e04fc0e59fbfdacdc7172b03ff3089a7a96c Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 10:49:47 +0800 Subject: [PATCH 3/7] Add logger in Encoder.java --- src/main/java/seedu/cafectrl/storage/Encoder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/seedu/cafectrl/storage/Encoder.java b/src/main/java/seedu/cafectrl/storage/Encoder.java index d8b11e2de8..37ad3f1ae1 100644 --- a/src/main/java/seedu/cafectrl/storage/Encoder.java +++ b/src/main/java/seedu/cafectrl/storage/Encoder.java @@ -106,6 +106,7 @@ public static ArrayList encodePantryStock(Pantry pantry) { encodedIngredient.append(ingredient.getUnit()); encodedIngredient.append(System.lineSeparator()); pantryStockInString.add(encodedIngredient.toString()); + logger.info("Encoded ingredient: " + ingredient.getName()); } ArrayList pantryStockInStringHashed = hashEncoding(pantryStockInString); return pantryStockInStringHashed; From 9355626ef006c5d7dfa0e1fcf91dd8b3f36d37a2 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 10:52:05 +0800 Subject: [PATCH 4/7] Add logger in HelpCommand.java --- src/main/java/seedu/cafectrl/command/HelpCommand.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/seedu/cafectrl/command/HelpCommand.java b/src/main/java/seedu/cafectrl/command/HelpCommand.java index 4210bbe4e9..80e92e6902 100644 --- a/src/main/java/seedu/cafectrl/command/HelpCommand.java +++ b/src/main/java/seedu/cafectrl/command/HelpCommand.java @@ -1,21 +1,27 @@ package seedu.cafectrl.command; +import seedu.cafectrl.CafeCtrl; import seedu.cafectrl.ui.Ui; +import java.util.logging.Logger; + //@@author ziyi105 public class HelpCommand extends Command { public static final String COMMAND_WORD = "help"; public static final String MESSAGE_USAGE = "To view all commands:\n" + COMMAND_WORD; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Ui ui; + public HelpCommand(Ui ui) { this.ui = ui; } @Override public void execute() { + logger.info("Executing HelpCommand..."); ui.printLine(); ui.showHelp(); } From 05369bb82fee6647553221bdc23059374245e512 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 10:52:23 +0800 Subject: [PATCH 5/7] Add logger in EditPriceCommand.java --- src/main/java/seedu/cafectrl/command/EditPriceCommand.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java index 546947b9a6..6f72ac318a 100644 --- a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java +++ b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java @@ -1,10 +1,13 @@ package seedu.cafectrl.command; +import seedu.cafectrl.CafeCtrl; import seedu.cafectrl.data.Menu; import seedu.cafectrl.data.dish.Dish; import seedu.cafectrl.ui.ErrorMessages; import seedu.cafectrl.ui.Ui; +import java.util.logging.Logger; + //@@author ziyi105 /** * Edit the price of a dish of a certain index @@ -15,6 +18,7 @@ public class EditPriceCommand extends Command { + "edit_price dish/DISH_INDEX price/NEW_PRICE\n" + "Example: edit_price dish/1 price/4.50"; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Menu menu; protected Ui ui; private final int menuID; @@ -32,6 +36,7 @@ public EditPriceCommand(int menuID, float newPrice, Menu menu, Ui ui) { * Set new price of the dish and show edit price message */ public void execute() { + logger.info("Executing EditPriceCommand..."); Dish dish = menu.getDishFromId(this.menuID - Ui.OFFSET_LIST_INDEX); // Checks for original price From 6e99071983069d85d8da37e125c76235e56997b8 Mon Sep 17 00:00:00 2001 From: ziyi105 <82555990+ziyi105@users.noreply.github.com> Date: Sun, 12 Nov 2023 15:37:36 +0800 Subject: [PATCH 6/7] Update src/main/java/seedu/cafectrl/parser/Parser.java Co-authored-by: ShaniceTang <110757597+ShaniceTang@users.noreply.github.com> --- src/main/java/seedu/cafectrl/parser/Parser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index cf644bb55f..1e5469b4b1 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -214,7 +214,7 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u try { newPrice = parsePriceToFloat(matcher.group(newPriceGroup).trim()); } catch (ParserException e) { - logger.warning("Invalid price!"); + logger.log(Level.WARNING, "Invalid price!", e); return new IncorrectCommand(e.getMessage(), ui); } From 2f24c1e7700deebdeadff8d62a334034f70781b9 Mon Sep 17 00:00:00 2001 From: ziyi105 <82555990+ziyi105@users.noreply.github.com> Date: Sun, 12 Nov 2023 15:37:43 +0800 Subject: [PATCH 7/7] Update src/main/java/seedu/cafectrl/parser/Parser.java Co-authored-by: ShaniceTang <110757597+ShaniceTang@users.noreply.github.com> --- src/main/java/seedu/cafectrl/parser/Parser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index 1e5469b4b1..3e58e7d0ce 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -207,7 +207,7 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u return new IncorrectCommand(ErrorMessages.INVALID_DISH_INDEX, ui); } } catch (NumberFormatException e) { - logger.warning("Invalid dish index type!"); + logger.log(Level.WARNING, "Invalid dish index type!", e); return new IncorrectCommand(ErrorMessages.WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE, ui); }