source: src/main/java/agents/ai2014/group2/G2Logger.java@ 126

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

Initial import : Genius 9.0.0

File size: 981 bytes
Line 
1package agents.ai2014.group2;
2
3import java.io.FileWriter;
4import java.io.IOException;
5import java.io.PrintWriter;
6import java.util.ArrayList;
7
8class G2Logger {
9 FileWriter fileWriter = null;
10 PrintWriter printWriter;
11
12 ArrayList<String> Buffer = new ArrayList<String>();
13
14 G2Logger () {
15
16 }
17
18 void init (int partyNumber) {
19 try {
20 fileWriter = new FileWriter("./logs/party"+partyNumber+"log.txt");
21 printWriter = new PrintWriter(fileWriter);
22 } catch (IOException e) {
23 System.out.println("Could not create log for party " + partyNumber);
24 }
25 printWriter.println("Log for party:" + partyNumber);
26 printWriter.println("==========================================");
27 for(String s: Buffer) {
28 printWriter.println(s);
29 }
30 Buffer.clear();
31 printWriter.flush();
32 }
33
34 void log(String s) {
35 if(fileWriter == null) {
36 Buffer.add(s);
37 } else {
38 printWriter.println(s);
39 printWriter.flush();
40 }
41 }
42
43 boolean isInitialized() {
44 return fileWriter != null;
45 }
46}
Note: See TracBrowser for help on using the repository browser.