-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogging.java
More file actions
48 lines (40 loc) · 1.41 KB
/
Copy pathLogging.java
File metadata and controls
48 lines (40 loc) · 1.41 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
package com.sim.central;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
/**
* This class is used to statically access a {@link java.util.logging.Logger}.
* The logger uses a {@link java.util.logging.FileHandler} as a handler to write the log messages to a file.
* After displaying the log to the console, it is logged to the file specified by the {@link java.util.logging.FileHandler}.
* @author Dahai Guo
*/
public class Logging {
private static Logger logger = null;
public static boolean init(){
FileHandler fh = null;
SimpleFormatter formatterTxt = new SimpleFormatter();
try {
fh = new FileHandler(
RoadDesign.getProperty(RoadDesign.LOG_FILE_NAME)); // specifies the FileHandler write to the log file specified in the properties file
fh.setFormatter(formatterTxt);
} catch (SecurityException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
logger = Logger.getLogger("sim"); // Creates a new logger with the name "sim".
logger.setLevel(Level.ALL);
logger.addHandler(fh); // logs to the file specified by the FileHandler
return true; // initialization was successful
}
/**
* @return a reference to the static logger.
*/
public static Logger getLogger(){
return logger;
}
}