-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomLogger.java
More file actions
47 lines (39 loc) · 1.24 KB
/
Copy pathCustomLogger.java
File metadata and controls
47 lines (39 loc) · 1.24 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
package edu.neu.csye6200.ca;
import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
/*
* @author: Dileep Reddy
* NUID: 001063317
* Class Description: this class creates a logger along with file handler and returns it to the class
* It a common class and can be accessed by all classes to create logger and file handler in one shot which gives us redundancy
*/
public class CustomLogger {
int LOG_SIZE = 20000;
int LOG_ROTATION_COUNT = 100;
private Logger logger;
private String className;
public CustomLogger(String className) {
this.className = className;
logger = Logger.getLogger(className);
}
public Logger getLoggerAndFileHandler()
{
try {
Handler handler;
String sep = File.separator;
String logPath = ".." + sep + "logs" + sep + className +".log";
handler = new FileHandler(logPath, LOG_SIZE, LOG_ROTATION_COUNT);
handler.setFormatter(new SimpleFormatter());
logger.addHandler(handler);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return logger;
}
}