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
|
Rev | Line | |
---|
[1] | 1 | package agents.ai2014.group2;
|
---|
| 2 |
|
---|
| 3 | import java.io.FileWriter;
|
---|
| 4 | import java.io.IOException;
|
---|
| 5 | import java.io.PrintWriter;
|
---|
| 6 | import java.util.ArrayList;
|
---|
| 7 |
|
---|
| 8 | class 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.