-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorLog.java
More file actions
62 lines (42 loc) · 1.74 KB
/
ErrorLog.java
File metadata and controls
62 lines (42 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/** Outputs program errors
*
* ErrorLog class
* @author Danny Guan
* @version 2
*/
import java.io.*;
import java.util.Date;
import java.text.SimpleDateFormat;
public class ErrorLog {
public void OutputLog(String errorType, String received, int lineError){
try {
// Prints out errors in log.txt
File errorLog = new File("ErrorLog.txt");
FileWriter fileWrite = new FileWriter(errorLog, true);
PrintWriter printWrite = new PrintWriter(fileWrite);
// Date of when the error was logged
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String formattedDate = sdf.format(date);
printWrite.println(formattedDate);
// No requests made
if (errorType.equals("No requests")){
printWrite.println(">No requests made.");
// No inputs made
} else if (errorType.equals("No inputs")){
printWrite.println(">No inputs made.");
// Wrong input type
} else if (errorType.equals("Wrong Input type")){
printWrite.println(">Input error, wrong input type.");
printWrite.println(">Input error on line: " + lineError + ", email expected, received: " + received + ".");
// Wrong input size
} else if (errorType.equals("Wrong Input size")){
printWrite.println(">Input error, wrong input size.");
printWrite.println(">Input error on line: " + lineError + ", email expected, received: " + received + ".");
}
printWrite.close();
} catch (Exception e){
System.out.println("error");
}
}
}