-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogging.java
More file actions
37 lines (29 loc) · 1.01 KB
/
Copy pathLogging.java
File metadata and controls
37 lines (29 loc) · 1.01 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
import java.io.IOException;
import java.util.logging.*;
public class Logging {
public static Logging instance;
private static Logger logger = Logger.getLogger("GardenLog");
// Using singleton for global access
public static Logging getInstance() {
if (instance == null) {
instance = new Logging();
}
return instance;
}
public void log(String message) {
FileHandler fh;
try {
// This block configure the logger with handler and formatter
fh = new FileHandler("GardenLog.log", true);
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
// the following statement is used to log any messages
logger.info(message);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}