Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2021S1#50 from manuelmanuntag96/Manue…
Browse files Browse the repository at this point in the history
…l-Logging

Implemented Logging for LogInCommand.java
  • Loading branch information
yeapcl authored Oct 14, 2020
2 parents 0577642 + c65d15c commit bd53c87
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT
AddCommand.log
LogInCommand.log.1
LogInCommand.log
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AddCommand(String input) {
super(input);
}

private static Logger logger = Logger.getLogger("LogAddCommand");
private static Logger logger = Logger.getLogger("LogLogInCommand");

@Override
public void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) throws DukeException {
Expand Down
33 changes: 31 additions & 2 deletions src/main/java/seedu/duke/command/LogInCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
import seedu.duke.user.User;
import seedu.duke.user.UserList;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
* Adds an event to the task list.
*/
Expand All @@ -17,18 +24,22 @@ public LogInCommand(String input) {
super(input);
}

private static Logger logger = Logger.getLogger("LogAddCommand");

@Override
public void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) throws DukeException {
boolean doesExist = false;
setupInputLogger();

String[] parsedInputs = input.split(" /", 2);
for (int i = 1; i < users.getTotalUserCount(); i++) {
for (int i = 1; i <= users.getTotalUserCount(); i++) {
if (parsedInputs[0].equals((users.getUser(i)).getName())) {
if (parsedInputs[1].equals((users.getUser(i)).getPassWord())) {
currentUser = users.getUser(i);
//System.out.println(parsedInputs[0] + " == " + (users.getUser(i)).getName());
doesExist = true;
} else {
logger.log(Level.WARNING,"Wrong Password" + "\n");
throw new DukeException("Wrong Password");
}
}
Expand All @@ -39,11 +50,29 @@ public void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) th
User newUser = new User(parsedInputs[0], parsedInputs[1]);
currentUser = newUser;
users.addUser(newUser);

logger.log(Level.INFO,"User Name successfully added: " + parsedInputs[0]);
logger.log(Level.INFO,"Password successfully added: " + parsedInputs[1] + "\n");
}
ui.greetUser(currentUser);
isLogIn = true;


logger.log(Level.INFO, "end of processing");

//storage.write(tasks);
}

private void setupInputLogger() {
LogManager.getLogManager().reset();
logger.setLevel(Level.ALL);
try {
FileHandler fh = new FileHandler("LogInCommand.log",true);
fh.setLevel(Level.INFO);
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);

} catch (IOException e) {
logger.log(Level.SEVERE,"File logging not working");
}
}
}

0 comments on commit bd53c87

Please sign in to comment.