Skip to content

Commit

Permalink
Add examples of lower-level log messages
Browse files Browse the repository at this point in the history
Let's add a few examples of lower-level log messages, to illustrate to
developers how they can be used in this codebase.
  • Loading branch information
Eclipse-Dominator committed Jul 29, 2023
1 parent a976ec9 commit be1696d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public void init() throws Exception {
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
logger.fine("Using data file : " + storage.getAddressBookFilePath());

Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
try {
Expand Down Expand Up @@ -108,11 +110,11 @@ protected Config initConfig(Path configFilePath) {
configFilePathUsed = Config.DEFAULT_CONFIG_FILE;

if (configFilePath != null) {
logger.info("Custom Config file specified " + configFilePath);
logger.fine("Custom Config file specified " + configFilePath);
configFilePathUsed = configFilePath;
}

logger.info("Using config file : " + configFilePathUsed);
logger.fine("Using config file : " + configFilePathUsed);

try {
Optional<Config> configOptional = ConfigUtil.readConfig(configFilePathUsed);
Expand Down Expand Up @@ -142,7 +144,7 @@ protected Config initConfig(Path configFilePath) {
*/
protected UserPrefs initPrefs(UserPrefsStorage storage) {
Path prefsFilePath = storage.getUserPrefsFilePath();
logger.info("Using preference file : " + prefsFilePath);
logger.fine("Using preference file : " + prefsFilePath);

UserPrefs initializedPrefs;
try {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;

import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
Expand All @@ -26,6 +28,7 @@ public class AddressBookParser {
* Used for initial separation of command word and args.
*/
private static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?<commandWord>\\S+)(?<arguments>.*)");
private static final Logger logger = LogsCenter.getLogger(AddressBookParser.class);

/**
* Parses user input into command for execution.
Expand All @@ -42,6 +45,12 @@ public Command parseCommand(String userInput) throws ParseException {

final String commandWord = matcher.group("commandWord");
final String arguments = matcher.group("arguments");

// Note to developers: Change the log level in .... (config.json) to enable lower level (i.e., FINE and lower)
// log messages such as the one below.
// Currently, lower level log messages are used sparingly, to minimize noise in the code.
logger.fine(String.format("Command word: %s ; Arguments: %s", commandWord, arguments));

switch (commandWord) {

case AddCommand.COMMAND_WORD:
Expand Down Expand Up @@ -69,6 +78,7 @@ public Command parseCommand(String userInput) throws ParseException {
return new HelpCommand();

default:
logger.finer("This user input caused a ParseException: " + userInput);
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
}
Expand Down

0 comments on commit be1696d

Please sign in to comment.