-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.java
More file actions
34 lines (28 loc) · 944 Bytes
/
Copy pathLogger.java
File metadata and controls
34 lines (28 loc) · 944 Bytes
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
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Logger {
BufferedWriter writer;
public void init(String fileName) {
try{
writer = new BufferedWriter(new FileWriter(fileName));}catch (IOException e){
System.out.println("There was an exception creating the log file "+e.toString());
}
}
public void LOG(String str) {
try {
writer.write(str+"\n");
} catch (IOException ioException) {
System.out.println(ioException.toString());
}
}
public void printLOG(String str){
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
LOG(timeStamp+": "+str);
System.out.println(timeStamp+": "+str);
}
public void close() {
try{
writer.close();}catch (Exception e){e.printStackTrace();}
}
}