source: src/main/java/parties/in4010/q12015/group7/Logger.java@ 3

Last change on this file since 3 was 1, checked in by Wouter Pasman, 7 years ago

Initial import : Genius 9.0.0

File size: 1.1 KB
Line 
1package parties.in4010.q12015.group7;
2
3import java.io.FileNotFoundException;
4import java.io.PrintWriter;
5import java.io.UnsupportedEncodingException;
6import java.text.DateFormat;
7import java.text.SimpleDateFormat;
8import java.util.Date;
9
10/**
11 * Logger to get detailed log information in a log-file even when tournaments
12 * are run
13 *
14 * @author svanbekhoven
15 *
16 */
17public class Logger {
18 private PrintWriter writer;
19 private boolean print;
20
21 public Logger(boolean print) {
22 this.print = print;
23
24 if (this.print) {
25 try {
26 DateFormat dateFormat = new SimpleDateFormat(
27 "yyyyMMdd_HHmmdss.SSS");
28 Date date = new Date();
29 writer = new PrintWriter("logs/manual_"
30 + dateFormat.format(date) + ".txt", "UTF-8");
31 } catch (FileNotFoundException e) {
32 e.printStackTrace();
33 } catch (UnsupportedEncodingException e) {
34 e.printStackTrace();
35 }
36 }
37 }
38
39 public void log(Object log) {
40 if (this.print) {
41 writer.print(log);
42 writer.flush();
43 }
44 }
45
46 public void logln(Object log) {
47 if (this.print) {
48 writer.println(log);
49 writer.flush();
50 }
51 }
52}
Note: See TracBrowser for help on using the repository browser.