-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemLog.java
More file actions
51 lines (51 loc) · 1.02 KB
/
Copy pathSystemLog.java
File metadata and controls
51 lines (51 loc) · 1.02 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
package Logger;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
import java.util.Date;
//Used to write a log to specified file
public class SystemLog {
String path;
//FileWriter fl;
public SystemLog(String path)// throws IOException
{
this.path=path;
/*try {
this.path=path;
File file = new File(path);
if(file.exists()==false)
{
file.createNewFile();
}
fl=new FileWriter(path,true);
}
catch(IOException e)
{
System.out.println(e);
}*/
}
public boolean log(String message) throws IOException
{
try {
this.path=path;
File file = new File(path);
if(file.exists()==false)
{
System.out.println("Creating log file...");
file.createNewFile();
System.out.println("Log created!");
}
FileWriter fl=new FileWriter(path,true);
Date date=new Date();
message= date.toString() +": "+ message+"\r\n";
fl.write(message);
fl.close();
return true;
}
catch(IOException e)
{
System.out.println(e);
return false;
}
}
}